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

Get orders total purchases amount for the day in Woocommerce

The best and effective way to get that is to use the following very light SQL query, that will get the sum of all order totals in the last 24 hours for “processing” and “completed” orders statuses: function get_daily_purchases_total(){ global $wpdb; return $wpdb->get_var( ” SELECT SUM(pm.meta_value) FROM {$wpdb->prefix}posts as p INNER JOIN {$wpdb->prefix}postmeta as pm … Read more

Get refunded orders and refunded order items details in Woocommerce 3

To get refunded orders you could use some dedicated WC_Order methods like the following ones that have Item Id as argument: $item_qty_refunded = $order->get_qty_refunded_for_item( $item_id ); // Get the refunded amount for a line item. $item_total_refunded = $order->get_total_refunded_for_item( $item_id ); // Get the refunded amount for a line item. You can access an array WC_Order_Refund … Read more

Custom order status background button color in Woocommerce 3.3 admin order list

You can set CSS color and background color to your custom order status displayed in admin order list this way: add_action(‘admin_head’, ‘styling_admin_order_list’ ); function styling_admin_order_list() { global $pagenow, $post; if( $pagenow != ‘edit.php’) return; // Exit if( get_post_type($post->ID) != ‘shop_order’ ) return; // Exit // HERE we set your custom status $order_status=”Dispatched”; // <==== HERE … Read more

Change sender name and email address for specific WooCommerce email notifications

The sender name and email address are set here (at the end of Woocommerce “Emails” setting tab: This fields are passed through dedicated filters hook that allow you to change conditionally the values. Here is an example conditionally restricted to “customer processing email notification”: // Change sender name add_filter( ‘woocommerce_email_from_name’, function( $from_name, $wc_email ){ if( … Read more

Send an Email notification to the admin for pending order status in WooCommerce

UPDATE 2 (Change from woocommerce_new_order to woocommerce_checkout_order_processed thanks to CĂ©line Garel) This code will be fired in all possible cases when a new order get a pending status and will trigger automatically a “New Order” email notification: // New order notification only for “Pending” Order status add_action( ‘woocommerce_checkout_order_processed’, ‘pending_new_order_notification’, 20, 1 ); function pending_new_order_notification( $order_id … Read more