Display custom order meta data value in email notifications WooCommerce

You have some minor mistakes, via the if condition “$email->id == …” you can target the mails How to target other WooCommerce order emails ‘customer_completed_order’ ‘customer_processing_order’ ‘customer_on_hold_order’ ‘customer_refunded_order’ ‘customer_reset_password’ ‘customer_invoice’ ‘customer_new_account’ ‘customer_note’ ‘cancelled_order’ ‘failed_order’ ‘new_order’ function woocommerce_email_order_invoice_number( $order, $sent_to_admin, $plain_text, $email ) { // For ‘new order’ if ( $email->id == ‘new_order’ ) { // … Read more

Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4

Updated Since Woocommerce version 3, woocommerce_checkout_create_order_line_item action hook now replace outdated woocommerce_add_order_item_meta hook in a much better way using the new introduced CRUD getters and setters methods: // Save custom data to order item meta data add_action( ‘woocommerce_checkout_create_order_line_item’, ‘tshirt_order_meta_handler’, 20, 4 ); function tshirt_order_meta_handler( $item, $cart_item_key, $values, $order ) { $custom_designer = WC()->session->get( $cart_item_key.’_designer’ ); … Read more

Add a new custom field to WooCommerce checkout and display on admin order pages and email notifications

You’re using delivery_date, city_custom & Citymixed up, this gives you different values, so that is your problem // Display a custom checkout select field after Billing form add_action( ‘woocommerce_after_checkout_billing_form’, ‘my_custom_checkout_field’, 10, 1 ); function my_custom_checkout_field( $checkout ) { echo ‘<div id=”my_custom_checkout_field”> ‘ . __(‘City’) . ”; woocommerce_form_field( ‘city_custom’, array( ‘type’ => ‘select’, ‘options’ => array( … Read more

Allow re-sending New Order Notification in WooCommerce 5+

Since WooCommerce 5.0 a new filter hook has been added, that disables resending “New Order” email notification, restricting this specific notification to be sent only one time. This is what has been added to WC_Email_New_Order trigger() method (default is set to false): /** * Controls if new order emails can be resend multiple times. * … Read more

Woocommerce: Which hook to replace deprecated “woocommerce_add_order_item_meta”

2017/2018 THE RIGHT WAY (Using new CRUD setters and Getters methods) Related: Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4 Since woocommerce 3 that has improved many things making drastic changes, the action hook woocommerce_add_order_item_meta still work perfectly even in woocommerce version 3.3+. This hook is enabled by WC_Checkout class methods and related functions in the checkout … Read more

Display the discounted percentage near sale price in Single product pages for WC 3.0+

Updated – 2019 (avoid rounding price issue) – 2017 (avoid NAN% percentage value) woocommerce_sale_price_html hook has been replaced by a different hook in WooCommerce 3.0+, that has now 3 arguments (but not the $product argument anymore). add_filter( ‘woocommerce_format_sale_price’, ‘woocommerce_custom_sales_price’, 10, 3 ); function woocommerce_custom_sales_price( $price, $regular_price, $sale_price ) { // Getting the clean numeric prices … Read more

How to add custom stock status to products in WooCommerce 4+

Last update: 04/22 – Tested in WordPress 5.9.2 & WooCommerce 6.3.1 Code goes in functions.php file of the active child theme (or active theme). Use woocommerce_product_stock_status_options instead of woocommerce_product_options_stock_status. This way you can immediately add a status instead of replace the existing dropdown Also use woocommerce_get_availability_text & woocommerce_get_availability_class opposite woocommerce_get_availability. This way you don’t have … Read more

WooCommerce action hooks and overriding templates

First in reference below you will find how to override properly woocommerce templates via a theme (avoiding editing the plugin templates). In your first code snippet, as you can see for woocommerce_single_product_summary hook, you have in order all the different templates that are @hooked in this hook location with do_action() WordPress function: do_action( ‘woocommerce_single_product_summary’ ); … Read more