I tried the following code that is displaying a message to all those customers who should receive a customer_processing_order
and customer_completed_order
when local_pickup
is the chosen shipping method.
I noticed I do not store any _shipping_method item within any order meta, but only a thing like: order_item_type: shipping > method_id > local_pickup:3
How can I retrieve it?
I tried this of code without success:
// testo per Ritiro in Sede
add_action( 'woocommerce_email_order_details', 'my_completed_order_email_instructions', 10, 4 );
function my_completed_order_email_instructions( $order, $sent_to_admin, $plain_text, $email ) {
if( 'customer_processing_order' != $email->id ) return;
if ( method_exists( $order, 'get_id' ) ) {
$order_id = $order->get_id();
} else {
$order_id = $order->id;
}
$shipping_method_arr = get_post_meta($order_id, '_shipping_method', false);
$method_id = explode( ':', $shipping_method_arr[0][0] );
$method_id = $method_id[0]; // We get the slug type method
if ( 'local_pickup' == $method_id ){
echo '<p><strong>Ritiro in sede</strong></p>';
}
}