We've removed the payment information on our customer emails but can't remove the title. How do we do it?We're using Woocommerce email templates for order confirmation emails.
We've searched in and tried to change
email-order-details.php
email-order-items.php
customer-on-hold-order. php (our customer use on-hold-order as default template for confirmation emails to customers)
We tried this one in
email-order-details, it did not work at all.
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
if ( $total['label'] != 'Payment Method:' ){
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
}
?>
</tfoot>
To remove payment method from WooCommerce email notifications using hooks:
add_filter( 'woocommerce_get_order_item_totals', 'remove_paymeny_method_row_from_emails', 10, 3 );
function remove_paymeny_method_row_from_emails( $total_rows, $order, $tax_display ){
// On Email notifications only
if ( ! is_wc_endpoint_url() ) {
unset($total_rows['payment_method']);
}
return $total_rows;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Or overriding email-order-details.php template file:
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $key => $total ) {
$i++;
if ( $key !== 'payment_method' ){
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
}
?>
</tfoot>
It should also works.
Related
We are using Woocommerce Payments and on our order confirmation email the payment method comes up as Woocommerce Payments instead of the payment source such as Visa, Mastercard etc.
I have found how to remove the Payment method altogether (see below), but how would I remove this and add back in Payment Source?
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $key => $total ) {
$i++;
if ( $key !== 'payment_method' ){
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
}
?>
In your functions.php add this
add_filter( 'woocommerce_get_order_item_totals', 'change_payment_method_name_in_emails', 10, 3 );
function change_payment_method_name_in_emails( $total_rows, $order, $tax_display ){
// On Email notifications only
if ( ! is_wc_endpoint_url() ) {
if($total_rows['payment_method']['value'] === 'Woocommerce Payments'){
$total_rows['payment_method']['value'] = 'Visa/Master';
}
}
return $total_rows;
}
I'm looking for some help getting customize the attribute table on WooCommerce.
<table>
<?php foreach (array_chunk($product_attributes, 2) as $product_attribute_key => $product_attribute) :{ ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<?php foreach ($product_attribute as $value) :{ ?>
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $value['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $value['value'] ); ?></td>
<?php } endforeach; ?>
</tr>
<?php } endforeach; ?>
</table>
I tried modify the above snippet in order to break line between Attribute Name and Attribute Value to display the attributes like it is in the below picture.
attributes
Is there any easy hook to get this work?
Thanks in Advance.
Create child-theme in case of theme update to not lose your settings.
Create in child-theme folders /woocommerce/single-product/ and copy from woocommerce/templates/single-product the file product-attributes.php.
Change:
defined( 'ABSPATH' ) || exit;
if ( ! $product_attributes ) {
return;
}
?>
<table class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<tr class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<th class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></th>
<td class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></td>
</tr>
<?php endforeach; ?>
</table>
to
defined( 'ABSPATH' ) || exit;
if ( ! $product_attributes ) {
return;
}
$i = 0;
?>
<div class="woocommerce-product-attributes shop_attributes">
<?php foreach ( $product_attributes as $product_attribute_key => $product_attribute ) : ?>
<div class="woocommerce-product-attributes-item woocommerce-product-attributes-item--<?php echo esc_attr( $product_attribute_key ); ?>">
<div class="woocommerce-product-attributes-item__label"><?php echo wp_kses_post( $product_attribute['label'] ); ?></div>
<div class="woocommerce-product-attributes-item__value"><?php echo wp_kses_post( $product_attribute['value'] ); ?></div>
</div>
<?php
if ($i % 2 != 0){
echo '<div class="clear"></div>';
}
$i++;
endforeach; ?>
</div>
add CSS
/*2 Columnt style on product attributes*/
.woocommerce-product-attributes.shop_attributes .woocommerce-product-attributes-item {
float: left;
width: 50%;
margin-bottom: 8px;
padding-right:10px;
}
I'm working with the WooCommerce email-order-items.php and email-order-details.php template files. I'm trying to create some sort of 'if statement' that would replace item subtotal, total, and subtotal values with "TBD" (to be determined) if the value is equal to zero and then leave everything else as normal if the values are either negative or positive.
I've been trying to replace these lines in: wp-contents/themes/mytheme/woocommerce/emails/
'email-order-items.php': <?php echo $total['value']; ?>
'email-order-items.php': <?php echo $order->get_formatted_line_subtotal( $item ); ?>
For item subtotal
if($itemsubtotal == 0) {
$itemsubtotal = "TBD";
}
For total
if($total == 0) {
$total = "TBD";
}
For subtotal
if($subtotal == 0) {
$subtotal = "TBD";
}
EDIT
Change this line
<td class="td" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
TO
<?php if($total['value'] != 0){ ?>
<td class="td" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
<?php } else { ?>
<td class="td" style="text-align:left; <?php if ( $i === 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo "TBD"; ?></td>
<?php } ?>
Similarly for other variables it can be done.
I want to hide or remove VAT (tax) line from WooCommerce order emails. Result comes out from this function "get_order_item_totals()". Already I can hide tax label from emails by using following code.
function sv_change_email_tax_label( $label ) {
$label = '';
return $label;
}
add_filter( 'woocommerce_countries_tax_or_vat', 'sv_change_email_tax_label' );
I want to hide the entire row of VAT from order emails.
Finally figured out a way do this. "get_order_item_totals()" function returns an Array of arrays. so i unset() the unwanted array. in this case $totals[tax]
following is my code in email template.
<?php
if ( $totals = $order->get_order_item_totals() ) {
unset($totals[tax]);
$i = 0;
foreach ( $totals as $total ) {
$i++;
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
Thank you very much everyone who tried to help!
Regards!
Depending on the status of the order, you'll need to edit the relevant email template.
For eg: If you have COD payment method enabled and the customer selected that option, the order status will be "Processing", in that case you need to edit customer-processing-order.php template.
//find this line and after it add the following line of code
foreach ( $totals as $total ) {
//ensure to change "VAT" with the label that appears on your email
if( strstr( $total['label'], "VAT" ) ) continue;
This is my custom e-mail template which gets sent when a order is completed.
<?php
/**
* Customer completed order email
*
* #author WooThemes
* #package WooCommerce/Templates/Emails
* #version 1.6.4
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>
<?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<p><?php printf( __( "Hi there. Your recent order on %s has been completed. Your order details are shown below for your reference:", 'woocommerce' ), get_option( 'blogname' ) ); ?></p>
<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>
<h2><?php echo __( 'Order:', 'woocommerce' ) . ' ' . $order->get_order_number(); ?></h2>
<table cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
<thead>
<tr>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( true, false, true ); ?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text ); ?>
<?php do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text ); ?>
<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
<?php if ($order->billing_email) : ?>
<p><strong><?php _e( 'Email:', 'woocommerce' ); ?></strong> <?php echo $order->billing_email; ?></p>
<?php endif; ?>
<?php if ($order->billing_phone) : ?>
<p><strong><?php _e( 'Tel:', 'woocommerce' ); ?></strong> <?php echo $order->billing_phone; ?></p>
<?php endif; ?>
<?php wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) ); ?>
<?php do_action( 'woocommerce_email_footer' ); ?>
I want to insert PHP code there which connects to a database, does a select query which needs the article ID and how many of the article ID´s are purchased and then sends a new email with this data.
I tried it multiple times but at the end the mail always stopped working due to some PHP error which I couldn't address without debugging opportunity.
As an example I tried:
<?php
$db = mysqli_connect("sqwffwq", "qwfqwf", "qwfqwf", "qwfwqf");
// here I have no clue how to receive the article ID´s and there amounts...
// I wasn't able to find the woocommerce function
$result = mysqli_query('SELECT * FROM etc. etc. ');
mail(results) //Should be no problem after I got the information
?>
run this and see whats going on with each result. What you've failed to mention above is where you are adding this code, are you sure you have $order available?
global $wpdb;
$rere2 = substr( $order->get_order_number(), 4);
echo 'rere2='.$rere2.'<br>';
$myrows = $wpdb->get_results( 'SELECT * FROM wp_woocommerce_order_items WHERE order_id = "'.$rere2.'"' );
var_dump($myrows);
foreach ( $myrows as $myrow) {
//mail("etix#foxfiredev.net",$rere2,$myrow->order_item_id);
$x=wp_mail( "etix#foxfiredev.net", $rere2 ,$myrow->order_item_id);
echo $x.'<br>';
$wpdb->update( 'wp_woocommerce_order_items',
array('id'=>$variable),
array('order_item_id'=>$myrow->order_item_id),
); // change table name, column names and values to suit..
}
exit;