I want to remove or hide "shipping" label from woocommerce order confirmation Email table.
The following little code snippet will remove only the label "Shipping", from email notifications:
add_filter( 'woocommerce_get_order_item_totals', 'customize_email_order_line_totals', 1000, 3 );
function customize_email_order_line_totals( $total_rows, $order, $tax_display ){
// Only on emails notifications
if( ! is_wc_endpoint_url() || ! is_admin() ) {
// Remove "Shipping" label text from totals rows
$total_rows['shipping']['label'] = '';
}
return $total_rows;
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
To remove the shipping total line from email notifications, use the following instead:
add_filter( 'woocommerce_get_order_item_totals', 'customize_email_order_line_totals', 1000, 3 );
function customize_email_order_line_totals( $total_rows, $order, $tax_display ){
// Only on emails notifications
if( ! is_wc_endpoint_url() || ! is_admin() ) {
// Remove shipping line from totals rows
unset($total_rows['shipping']);
}
return $total_rows;
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
It's not possible to target a specific email notification.
Related
How to make the text with the name of the product in the woocommerce email be below the product image?
I want the letters to look good.
Updated: If the product image are displayed in your email notifications, you can try the following to display the product title under this image:
add_filter( 'woocommerce_order_item_name', 'product_title_under_thumbnail_emails', 10, 3 );
function product_title_under_thumbnail_emails( $item_name, $item, $is_visible ) {
// Targeting view order pages only
if( is_wc_endpoint_url() )
return $item_name;
// Get the WC_Product object (from order item)
$product = $item->get_product();
if( $product->get_image_id() > 0 && $is_visible )
$item_name = '<br>' . $item_name;
return $item_name;
}
Code goes in function.php file of your active child theme (or active theme). It should works.
This has been answered a while back but the filter is not working anymore. Not sure if it is deprecated or not. I am using both filters:
woocommerce_product_tax_class
woocommerce_product_get_tax_class
My function looks like:
function wc_diff_rate_for_user( $tax_class, $product ) {
$tax_class = "Zero rate";
return $tax_class;
}
add_filter( 'woocommerce_product_tax_class', 'wc_diff_rate_for_user', 1, 2 );
How can I set a tax class based on specific coupon in Woocommerce?
Since Woocommerce 3, the filter hook woocommerce_product_tax_class doesn't exist anymore, only new woocommerce_product_get_tax_class composite filter hook is available and works.
There is multiple ways to set a tax class based on an applied coupon code (In both examples below, we set "Zero rate" tax class when a defined coupon code is applied):
1) Using woocommerce_before_calculate_totals action hook, the best way:
add_action( 'woocommerce_before_calculate_totals', 'change_tax_class_based_on_specific_coupon', 25, 1 );
function change_tax_class_based_on_specific_coupon( $cart ) {
// Define your coupon code below
if ( ! $cart->has_discount('summer') )
return;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
if ( did_action( 'woocommerce_before_calculate_totals' ) >= 2 )
return;
foreach( $cart->get_cart() as $cart_item ){
// We set "Zero rate" tax class
$cart_item['data']->set_tax_class("Zero rate");
}
}
Code goes in function.php file of the active child theme (or active theme). Tested and works.
2) Using woocommerce_product_get_tax_class filter hook:
add_filter( 'woocommerce_product_get_tax_class', 'change_tax_class_based_on_specific_coupon', 30, 2 );
function change_tax_class_based_on_specific_coupon( $tax_class, $product ) {
// Define your coupon code below
if( WC()->cart->has_discount('summer') )
$tax_class = "Zero rate";
return $tax_class;
}
Code goes in function.php file of the active child theme (or active theme). Tested and works.
Let me clear my question:
I have downloaded & activated WooCommerce Plugin for E-Commerce Functionality.
I want to add "Applied coupon code" in Admin New Order Email Template using my custom plugin.
Now:
Can you tell me that exact Hook or Function which is actually setting up that New Order Email Template so that i will override it?
Can you tell me how to call applied coupon code, so that i will display this in email template?
It would be great, if you help me please.
This can be done using a custom function hooked in woocommerce_email_order_details action hook (for example) that will display in admin emails notifications the used coupons in the order:
// The email function hooked that display the text
add_action( 'woocommerce_email_order_details', 'display_applied_coupons', 10, 4 );
function display_applied_coupons( $order, $sent_to_admin, $plain_text, $email ) {
// Only for admins and when there at least 1 coupon in the order
if ( ! $sent_to_admin && count($order->get_items('coupon') ) == 0 ) return;
foreach( $order->get_items('coupon') as $coupon ){
$coupon_codes[] = $coupon->get_code();
}
// For one coupon
if( count($coupon_codes) == 1 ){
$coupon_code = reset($coupon_codes);
echo '<p>'.__( 'Coupon Used: ').$coupon_code.'<p>';
}
// For multiple coupons
else {
$coupon_codes = implode( ', ', $coupon_codes);
echo '<p>'.__( 'Coupons Used: ').$coupon_codes.'<p>';
}
}
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Tested and works...
This is because $coupon_codes is not an array() define it with $coupon_codes=array();
When the customer order is placed, I would like if free shipping has been used, to remove shipping info from the order confirmation mail to the customer.
Is it possible to achieve this?
This is possible with this custom hooked function (but from all email notifications):
add_filter( 'woocommerce_get_order_item_totals', function( $total_rows, $order, $tax_display ){
// Only for "Free Shipping" method
if( ! $order->has_shipping_method('free_shipping') || is_account_page() || is_wc_endpoint_url( 'order-received' ) )
return $total_rows;
unset($total_rows['shipping']);
return $total_rows;
}, 11, 3 );
Code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested and works.
I need to change the text (label) "Product" to "Ticket" in WooCommerce Order Item table email notifications.
How would I do this?
Is it possible?
Thanks
First we need to get the Email ID to target the all email notifications. The only way is to get it before and to set the value in a global variable.
Then in a custom function hooked in Wordpress gettext action hook, we can change (translate) "Product" in all email notifications.
Here is that code:
## Tested on WooCommerce 2.6.x and 3.0+
// Setting the email_is as a global variable
add_action('woocommerce_email_before_order_table', 'the_email_id_as_a_global', 1, 4);
function the_email_id_as_a_global($order, $sent_to_admin, $plain_text, $email){
$GLOBALS['email_id_str'] = $email->id;
}
add_filter('gettext', 'wc_renaming_email_label', 50, 3);
function wc_renaming_email_label( $translated_text, $untranslated_text, $domain ) {
// Getting the email ID global variable
$refNameGlobalsVar = $GLOBALS;
$email_id = $refNameGlobalsVar['email_id_str'];
if( !is_admin() && $email_id ) {
if( $untranslated_text == 'Product' )
$translated_text = __( 'Ticket', $domain );
}
return $translated_text;
}
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
This code is tested on WooCommerce from 2.6.x to 3.0+ and works.
If you don't want to modify the WooCommerce files, use this plugin https://wordpress.org/plugins/woo-custom-emails/
If you want to edit it from the WooCommerce files, then modify the email templates in /wp-content/plugins/woocommerce/templates/emails/