php - 在 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{
}
}
解决方案
解决方案在这里:我解决了我的问题
<?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{
}
}
}
推荐阅读
- javascript - 错误:没有设置QueryClient,使用QueryClientProvider设置一个
- java - ExternalContext 重定向导致 IllegalStateException
- python - 我可以在 FastAPI 中按标签分隔模式吗?
- spell-checking - 默认情况下,自定义搜索引擎不使用更正后的查询
- java - 将表中的两列映射到另一个表中的同一列时出现奇怪的异常
- c# - 如何从 WPF 中的另一种方法分配给列表?
- java - 方法内的行的执行顺序是什么 - Kotlin?
- git - 如何 git diff 分歧分支
- keras - 如果 nstep=-1 在 for..loop 中运行 GridSearchCV 时出错
- sql - 从字符串中提取数据 - SQL