Php 在WooCommerce电子邮件通知中检查用户是否免征增值税
在发送给管理员的WooCommerce新订单电子邮件通知中,我尝试在用户“免税”时显示“免税订单””附加文本,使用以下内容:Php 在WooCommerce电子邮件通知中检查用户是否免征增值税,php,wordpress,woocommerce,orders,user-data,Php,Wordpress,Woocommerce,Orders,User Data,在发送给管理员的WooCommerce新订单电子邮件通知中,我尝试在用户“免税”时显示“免税订单””附加文本,使用以下内容: add_action( 'woocommerce_email_before_order_table', 'add_content_specific_email', 20, 4 ); function add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) { // Onl
add_action( 'woocommerce_email_before_order_table', 'add_content_specific_email', 20, 4 );
function add_content_specific_email( $order, $sent_to_admin, $plain_text, $email ) {
// Only for admin emails
if ( ! $sent_to_admin ) {
return;
}
if ( $email->id == 'new_order' && !(WC()->customer->get_is_vat_exempt()) && $sent_to_admin ){
return;
}
if ( $email->id == 'new_order' && WC()->customer->get_is_vat_exempt() && $sent_to_admin) {
echo '<h2 class="email-tax-free-title">Tax Free Order</h2></p>';
}
}
如何解决此错误?我的代码中有错误吗?已更新 您的代码中有一些错误。为避免此错误,您需要检查订单元数据
是否为“增值税免税”
值是否为“是”,如下所示:
add_action('woocommerce_email_在_order_表之前,'new_order_email_是免税的,'20,4');
功能新订单电子邮件免税($order,$sent,$to,$admin,$plain,$email){
//仅适用于新订单管理员电子邮件通知
如果($send_to_admin&&‘new_order’=$email->id){
//检查用户是否对当前订单免征增值税
如果('yes'==$order->get\u meta('is\u vat\u免税')){
echo“免税订单”;
}
}
}
代码进入活动子主题(或活动主题)的functions.php文件。已测试并运行。已更新 您的代码中有一些错误。为避免此错误,您需要检查订单元数据
是否为“增值税免税”
值是否为“是”,如下所示:
add_action('woocommerce_email_在_order_表之前,'new_order_email_是免税的,'20,4');
功能新订单电子邮件免税($order,$sent,$to,$admin,$plain,$email){
//仅适用于新订单管理员电子邮件通知
如果($send_to_admin&&‘new_order’=$email->id){
//检查用户是否对当前订单免征增值税
如果('yes'==$order->get\u meta('is\u vat\u免税')){
echo“免税订单”;
}
}
}
代码进入活动子主题(或活动主题)的functions.php文件。经过测试,工作正常。嗨!非常感谢你。我试过了,但是没有在新订单中打印出来。我的set\u vat\u EXPORT()函数工作正常。我仅在一些计费国家/地区设置set_vat_EXPLOVE()=是。通过在WooCommerce中与增值税免税国家签订订单,结果是增值税免税=是。嗨!非常感谢你。我试过了,但是没有在新订单中打印出来。我的set\u vat\u EXPORT()函数工作正常。我仅在一些计费国家/地区设置set_vat_EXPLOVE()=是。通过在WooCommerce中与增值税免税国家签订订单,结果是增值税免税=是。
Uncaught Error: Call to a member function get_is_vat_exempt() on null
#0 /home/site/public_html/wp-includes/class-wp-hook.php(287): add_content_specific_email(Object(Automattic\WooCommerce\Admin\Overrides\Order), true, false, Object(WC_Email_New_Order))
#1 /home/site/public_html/wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array)
#2 /home/site/public_html/wp-includes/plugin.php(478): WP_Hook->do_action(Array)
#3 /home/site/public_html/wp-content/plugins/woocommerce/templates/emails/email-order-details.php(22): do_action('woocommerce_ema...', Object(Automattic\WooCommerce\Admin\Overrides\Order), true, false, Object(WC_Email_New_Order))
#4 /home/site/public_html/wp-content/plugins/woocommerce/includes/wc-core-functions.php(344): include('/home/site/...')
#5 /home/site/public_html/wp-content/plugins/woocommerce/includes/class-wc-emails.php(421): wc_get