首页 > 解决方案 > 在 woo-commerce 默认电子邮件功能中添加修改

问题描述

我正在尝试在 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{

}
}

标签: phpemailwoocommercehook-woocommercecustom-wordpress-pages

解决方案


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

  <?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{

 }

    }
}

推荐阅读