2

I would like to add the chosen shipping method to the top of my woocommerce 'new order' emails.

I would also like to add the selected time slot (custom field: jckwds_timeslot) next to this.

I know I need to add PHP code to the functions.php file, but I'm unsure how.

This is the code I've already used to add the order time at the top of the emails:

add_action( 'woocommerce_email_order_details', 'custom_processing_order_notification', 1, 4 );
function custom_processing_order_notification( $order, $sent_to_admin, $plain_text, $email ) {
    // Only for processing email notifications to customer
    if( ! 'customer_processing_order' == $email->id ) return;

    $date_modified = $order->get_date_modified();
    $date_paid = $order->get_date_paid();

    $date =  empty( $date_paid ) ? $date_modified : $date_paid;

    echo sprintf( '<p>Order NO. %s (placed at <time>%s</time>)</p>',
        $order->get_order_number( ),
        $date->date("g:i A")
    );
}
CRJDesign
  • 23
  • 2

1 Answers1

1

You can use $order->get_shipping_method() to retrieve the order's shipping method. And you can use $order->get_meta() to retrieve custom field values.

add_action( 'woocommerce_email_order_details', 'custom_processing_order_notification', 1, 4 );
function custom_processing_order_notification( $order, $sent_to_admin, $plain_text, $email ) {
    // Only for processing email notifications to customer
    if( ! 'customer_processing_order' == $email->id ) return;

    //Date
    $date =  empty( $date_paid ) ? $order->get_date_modified() : $order->get_date_paid();
    printf( '<p>Order NO. %s (placed at <time>%s</time>)</p>', $order->get_order_number(), $date->date("g:i A") );

    //Shipping method
    printf( '<p>Shipping method: %s</p>', $order->get_shipping_method() );

    //Time slot
    printf( '<p>Time slot: %s</p>', $order->get_meta( 'jckwds_timeslot', true ) );
}
Terminator-Barbapapa
  • 3,063
  • 2
  • 5
  • 16