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;
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;
}
Hi there so I'm pretty new to php in woocommerce. I need to try and get the discount to show for each product in the invoice and was wondering if anyone could help with this.
So far I have been able to figure out this part and my only problem is getting the discount to show up.
<?php
$items = $this->get_order_items();
$discount = $order->get_discount_to_display();
if( sizeof( $items ) > 0 ) : foreach( $items as $item_id => $item ) : ?>
<tr class="<?php echo apply_filters( 'wpo_wcpdf_item_row_class', $item_id, $this->type, $this->order, $item_id ); ?>">
<td class="quantity"><?php echo $item['quantity']; ?></td>
<td class="discount"><?php echo $discount ?></td>
<td class="price"><?php echo $item['order_price']; ?></td>
i m using your code in my invoice template it shows me 0$ discount for every order??
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.
In WooCommerce I have a problem on my thankyou page (once the customer has placed his order). I have tryed to change it manualy but the problem is that the code is generated in an unknown file which I can't find.
<tfoot>
<?php
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo $total['label']; ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
?>
</tfoot>
This code give me all information in my order like a coupon the shipping etc.
On this picture I would like to replace the text in the black bordered rectangle (Here 'Gesamt:' mean "Total" by "Total inkl. vat"
Also I want to remove the red bordered rectangle block: "Inkl. 19% MwSt.".
Is it possible?
How can I do it?
Thanks.
Here the extract of the end on woocommerce/order/order-details.php template that is loaded in thank you page.
To override the 'Total' text displayed by foreach loop with the method get_order_item_totals() applied to the $order object (that generate an array of key/values), you have to add a condition for each language used by your web site. Here in my code you got english and german.
In your active theme go to woocommerce > order, and open/edit
order-details.php template file.
Replace the end of your template with this:
<tfoot>
<?php
$order_item_totals = $order->get_order_item_totals();
$count_lines = count($order_item_totals) - 1;
$count = 0;
foreach ( $order_item_totals as $key => $total ) {
$count++;
// The condition to replace "Total:" text in english and german
if( $total['label'] == 'Total:' || $total['label'] == 'Gesamt:')
$total_label = __( 'Total inkl. vat:', 'woocommerce' );
else
$total_label = $total['label'];
// End of the condition
?>
<tr>
<th scope="row"><?php echo $total_label; // <== == Replaced $total['label'] by $total_label ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
// this should avoid displaying last line
if( $count >= $count_lines ) break;
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_order_details_after_order_table', $order ); ?>
<?php if ( $show_customer_details ) : ?>
<?php wc_get_template( 'order/order-details-customer.php', array( 'order' => $order ) ); ?>
<?php endif; ?>
Now you can save, you are doneā¦
This code is tested and works.
References:
Template Structure + Overriding Templates via a Theme
Woocommerce template checkout > review-order.php
Customize the text "Total" in WooCommerce checkout page
Hey I think this would work for you
Just make sure that inkl. 19%.... is correctly written.
foreach ( $order->get_order_item_totals() as $key => $total ) {
?>
<tr>
<th scope="row"><?php echo ($total['label']=='inkl. 19% Mwst.'?'Vat Only':$total['label']); ?></th>
<td><?php echo $total['value']; ?></td>
</tr>
<?php
}
I am trying to develop a plugin that send the customer a "gift receipt" upon completing an order. I have everything working perfectly except I am unable to strip the price from the emails. When I try to edit the email-order-items.php template and remove the price column then the emails come in blank.
Specifically this is for downloadable products so the download links no longer show when I make any edits to the email-order-items file. And I would only want it to strip the price from the gift receipt emails not the other emails.
What I have done:
in my plugin I call on a email template "customer-gift-receipt.php" which is pretty much the same as "customer-processing-order.php" that comes package with Woocommerce.
In the file there is this line that brings in the email-order-items template and shows the links and price
<?php echo $order->email_order_items_table( $order->is_download_permitted(),
true, ($order->status=='processing') ? true : false ); ?>
This is the email-order-items template.
No matter what I do I cannot seem to get those prices stripped from just the customer-gift-receipt.php emails. Specifically it is this line in the above template:
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">
<?php echo $order->get_formatted_line_subtotal( $item ); ?>
</td>
I tried creating a duplicate of the email-order-items template and removing that line then calling it in my plugin and that did not work. I also tried copying the email-order-items template inside of the customer-gift-receipt.php file in the appropriate section and that failed as well. I had to define $items = $order->get_items(); when I tried copying email-order-items directly into the customer-gift-receipt template for it to somewhat work.
So can anyone suggest a way for me to strip the prices out of my customer-gift-receipt templates?
I have checked through these links:
Class WC_Order
Class WC_Email_Customer_Processing_Order
UPDATE:
I just found this link which should help me bring in email_order_items_table outside of the class: https://gist.github.com/mikejolley/1965842
When I try to add the above code in my customer-email-receipt template and place an order I get this error:
Fatal error: Class 'order_item_meta' not found in
.../.../.../.../woocommerce/emails/customer-gift-receipt.php on line 41"
Disable e-mail order items table from e-mail template and copy the function as a custom function into your theme.
<tbody>
<?php //echo $order->email_order_items_table( $order->is_download_permitted(), true, ($order->status=='processing') ? true : false );
echo custom_order_table($order);
?>
</tbody>
I had to remove download and variations which causes *Fatal Error with Class 'order_item_meta'* error. So your custom function will look like:
function custom_order_table($order,$price = false) {
foreach($order->get_items() as $item) :
$_product = $order->get_product_from_item( $item );
$file = $sku = $variation = $image = '';
if ($show_image) :
$src = wp_get_attachment_image_src( get_post_thumbnail_id( $_product->id ), 'thumbnail');
$image = apply_filters('woocommerce_order_product_image', '<img src="'.$src[0].'" alt="Product Image" height="'.$image_size[1].'" width="'.$image_size[0].'" style="vertical-align:middle; margin-right: 10px;" />', $_product);
endif;
if ($show_sku && $_product->get_sku()) :
$sku = ' (#' . $_product->get_sku() . ')';
endif;
$return .= '<tr>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">'. $image . apply_filters('woocommerce_order_product_title', $item['name'], $_product) . $sku . $file . $variation . '</td>
<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">'.$item['qty'].'</td>';
if ($price):
$return .= '<td style="text-align:left; vertical-align:middle; border: 1px solid #eee;">';
if ( $order->display_cart_ex_tax || !$order->prices_include_tax ) :
$ex_tax_label = ( $order->prices_include_tax ) ? 1 : 0;
$return .= woocommerce_price( $order->get_line_subtotal( $item ), array('ex_tax_label' => $ex_tax_label ));
else :
$return .= woocommerce_price( $order->get_line_subtotal( $item, true ) );
endif;
$return .= '</td>';
endif;
$return .= '</tr>';
// Show any purchase notes
if ($show_purchase_note) :
if ($purchase_note = get_post_meta( $_product->id, '_purchase_note', true)) :
$return .= '<tr><td colspan="3" style="text-align:left; vertical-align:middle; border: 1px solid #eee;">' . apply_filters('the_content', $purchase_note) . '</td></tr>';
endif;
endif;
endforeach;
echo $return;
}