在woocommerce中向管理员电子邮件添加订单备注

时间:2018-01-09 19:11:15

标签: php wordpress woocommerce orders email-notifications

我正在尝试将woocommerce结帐页面中的order_comments字段添加到新订单管理员电子邮件中。

以下是我对其他领域的处理方式(适用于有条件的运输方式):

INNER JOIN

添加下一行无济于事:

add_action ('woocommerce_email_customer_details', 'custom_email_customer_details', 15, 4);
function custom_email_customer_details( $order, $sent_to_admin, $plain_text, $email ){

    // Only for "New Order" email notification
    if ( 'new_order' != $email->id ) return;

    // Only "Flat Rate" Shipping Method
    if ( $order->has_shipping_method('flat_rate') ) {
        $order_id = $order->get_id(); // The Order ID

        // Test output
        echo '<table>';
        echo '<tr>';
        echo '<td>';
                 echo '<br><strong>'.__('Имя').':</strong> ' . get_post_meta( $order->id, '_billing_first_name', true ); 
        echo '<br><strong>'.__('Фамилия').':</strong> ' . get_post_meta( $order->id, '_billing_last_name', true );
                     echo '<br><strong>'.__('Метод доставки: Доставка курьером по Киеву').'</strong> '; 
         echo '<br><strong>'.__('Улица').':</strong> ' . get_post_meta( $order->id, '_shipping_address_1', true ); 
        echo '<br><strong>'.__('Дом').':</strong> ' . get_post_meta( $order->id, '_shipping_address_2', true );
        echo '<br><strong>'.__('Подъезд').':</strong> ' . get_post_meta( $order->id, '_shipping_city', true ) ;
        echo '<br><strong>'.__('Этаж').':</strong> ' . get_post_meta( $order->id, '_shipping_state', true ) ; 
        echo '<br><strong>'.__('Квартира').':</strong> ' . get_post_meta( $order->id, '_shipping_postcode', true ) ;
        echo '<br><strong>'.__('Время доставки').':</strong> ' . get_post_meta( $order->id, 'Время доставки', true ) ;
        echo '<br><strong>'.__('Комментарий покупателя').':</strong> ' .    ( $order->id, 'order_comments', true ) ;
        echo '</td>';
        echo '</tr>';
        echo '</table>';
                $mailer = WC()->mailer();

    remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20, 4 );

    }

那么我做错了什么? 提前致谢

1 个答案:

答案 0 :(得分:1)

如果您尝试获取订单客户备注,则需要使用以下WC_Order方法:

echo '<br><strong>'.__('Order notes').':</strong> '.$order->get_customer_note();

同样$order->id已过时,并被WooCommerce 3 +中的$order->get_id()取代。

获取$order时,您可以在代码中WC_Order上使用add_action ('woocommerce_email_customer_details', 'custom_email_customer_details', 15, 4); function custom_email_customer_details( $order, $sent_to_admin, $plain_text, $email ){ // Only for "New Order" email notification if ( 'new_order' != $email->id ) return; // Only for "Flat Rate" Shipping Method if ( ! $order->has_shipping_method('flat_rate') ) return; // Test output echo '<table><tr> <td><br> <strong>'.__('Имя').':</strong> '.$order->get_billing_first_name().'<br> <strong>'.__('Фамилия').':</strong> '.$order->get_billing_last_name().'<br> <strong>'.__('Метод доставки: Доставка курьером по Киеву').'</strong> <br> <strong>'.__('Улица').':</strong> '.$order->get_shipping_address_1().'<br> <strong>'.__('Дом').':</strong> '.$order->get_shipping_address_2().'<br> <strong>'.__('Подъезд').':</strong> '.$order->get_shipping_city().'<br> <strong>'.__('Этаж').':</strong> '.$order->get_shipping_state().'<br> <strong>'.__('Квартира').':</strong> ' . $order->get_shipping_postcode().'<br> <strong>'.__('Время доставки').':</strong> ' . get_post_meta( $order->get_id(), 'Время доставки', true ).'<br> <strong>'.__('Комментарий покупателя').':</strong> ' . $order->get_customer_note().' </td> </tr></table>'; $mailer = WC()->mailer(); remove_action( 'woocommerce_email_customer_details', array( $mailer, 'email_addresses' ), 20, 4 ); } 对象的实例代替:

String