Get different email for Sample Product order
-
Hi, I want to send different email for sample product order. Can you give me any tips to do this?
I am trying to add a function on this hook woocommerce_order_status_pending_to_processing_notification
and get meta value using wc_get_order_item_meta function. Please take a look inside my code and give any suggestion.Thanks
add_action( 'woocommerce_order_status_pending_to_processing_notification', 'trigger',10,2 ); function trigger( $order_id, $post ) { // bail if no order ID is present if ( ! $order_id ) return; // setup order object $to = "[email protected]"; $order_details = new WC_Order($order_id); $OrderId = $order_details->id; $items = $order_details->get_items(); $order_item_count = count($items); $print_result .= "Total Items: $order_item_count ,"; foreach ( $items as $item ) { if ( function_exists( 'woocommerce_get_order_item_meta' ) ) { $item_id = $item['product_id']; // <= Here is your product ID $result = wc_get_order_item_meta($item_id, "product type", true); $res = $data[0]['meta_value']; if($res == null){ $print_result .= "<br/>data[0][meta_value] is null"; }else{ $print_result .= "<br/>data[0][meta_value] is not null"; $print_result .= "<br/>data[0][meta_value]: $res"; } $status = wp_mail($to, "Order Details", $print_result); $status = wp_mail($to, "Order Details", "message working"); } } }
- The topic ‘Get different email for Sample Product order’ is closed to new replies.