dsfovbm931034814 2018-04-15 08:32
浏览 29
已采纳

自定义电子邮件缺失产品和小计

I have a custom email that I created on New Orders. The aim is to let the client & the admin know that a new order has been finished (not paid). For that reason this order will be in pending. So this Email triggers when a New Order is created but when the administrator receives the email, products don't show up neither the correct subtotal. The total is right.

I am using a custom payment module but I think this is not the problem.

// New order notification only for "Pending" Order status
add_action( 'woocommerce_new_order', 'pending_new_order_notification', 20, 1 );

function pending_new_order_notification( $order_id ) {

    //global $product;

    // Get an instance of the WC_Order object
    $order = new WC_Order( $order_id );

    $items = $order->get_items();    

    // Only for "pending" order status
    if( ! $order->has_status( 'pending' ) ) return;
    

    $wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order'];

    ## -- Customizing Heading, subject (and optionally add recipients)  -- ##
    // Change Subject
    $wc_email->settings['subject'] = __('{site_title} - New customer manual 2 order ({order_number}) - {order_date}');
    // Change Heading
    $wc_email->settings['heading'] = __('New customer Pending Order 2'); 
    $wc_email->recipient .= ", $order->billing_email"; // Add email recipients (coma separated)
    

    // Send "New Email" notification (to admin)
    $wc_email->trigger( $order_id, $order );
    
    //WC()->mailer()->emails['WC_Email_New_Order']->trigger( $order->get_id(), $order );
   



}

enter image description here

</div>
  • 写回答

1条回答 默认 最新

  • doubi1797 2018-06-06 09:50
    关注

    Same here.

    I've tried with woocommerce_checkout_order_processed hook and it works.

    Here is the action : add_action( 'woocommerce_checkout_order_processed', 'pending_new_order_notification', 20, 1 );

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?