在woo-commerce默认电子邮件功能中添加修改

时间:2018-07-09 08:29:11

标签: php email woocommerce hook-woocommerce custom-wordpress-pages

我正在尝试添加 在WooCommerce的默认行为中添加一个修改,以便当订单总额超过$ 50时,向管理员发送电子邮件。

这是我的代码,但显示“内部服务器错误”

<?php
add_action( 'woocommerce_new_order', 'orderemail' );

function orderemail($orderid) {
global $woocommerce;
$order = floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart- 
>get_cart_total() ) );
if($order > 50){
  // Get an instance of the WC_Email_New_Order object
$wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order'];

// Send "New Email" notification (to admin)
  $wc_email->trigger( $order_id );
}
else{

}
}

1 个答案:

答案 0 :(得分:0)

解决方案在这里:我解决了我的问题

  <?php


//  ========================================================================================
//  =  when an order total above $50 is placed then shoot an email to the admin.   =
//  =====================================================================================

    remove_action( 'woocommerce_order_status_pending_to_processing_notification', array( 
    $email_class->emails['WC_Email_New_Order'], 'trigger' ) );
    }


       add_action( 'woocommerce_thankyou', 'my_order_email1');


       function my_order_email1($order_id) {
    global $woocommerce;
    $order = wc_get_order($order_id);
    foreach ($order->get_items() as $item_id => $item_data) {
    $item_total = $item_data->get_total();

        if($item_total > 50){
     //Get an instance of the WC_Email_New_Order object
         $wc_email = WC()->mailer()->get_emails()['WC_Email_New_Order'];
       // Send "New Email" notification (to admin)
        $wc_email->trigger($order_id);
}
 else{

 }

    }
}