在woo-commerce默认邮箱功能中添加修改

Add modification in the woo-commerce default email feature

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

这是我的代码,但它显示 "internal server error"

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

}
}

这里有一个解决方案:我解决了我的问题

  <?php


//  ========================================================================================
//  =  when an order total above  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{

 }

    }
}