大佬教程收集整理的这篇文章主要介绍了根据 WooCommerce 订单中的用户角色显示自定义税收总行,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在 WooCommerce 中建立一个网上商店,我需要在订单电子邮件中显示正确的税费。我有 2 个不同的用户角色:“私人”和“企业”
以下代码进行税费计算并将其添加到新行中。但是,对于“业务”用户角色,我需要输出为 0DKK(因为他们支付的价格不含税):
// Add @R_905_10586@l taxes as a separated line before order @R_905_10586@l on orders and emails
add_filter( 'woocommerce_get_order_item_@R_905_10586@ls','insert_custom_line_order_item_@R_905_10586@ls',10,3 );
function insert_custom_line_order_item_@R_905_10586@ls( $@R_905_10586@l_rows,$order,$tax_display ){
// display only the gran @R_905_10586@l amount
$gran_@R_905_10586@l = (float) $order->get_@R_905_10586@l();
$@R_905_10586@l_rows['order_@R_905_10586@l']['value'] = is_wc_endpoint_url() ? $@R_905_10586@l_HTML : Strip_Tags( $@R_905_10586@l_HTML );
// Custom tax calculation (for 20% tax ratE)
$@R_905_10586@l_tax_amount = wc_price( $gran_@R_905_10586@l - $gran_@R_905_10586@l / 1.25 );
$@R_905_10586@l_tax_amount = is_wc_endpoint_url() ? $@R_905_10586@l_tax_amount : Strip_Tags( $@R_905_10586@l_tax_amount );
// Create a new row for @R_905_10586@l tax
$tax_row = array( 'order_tax_@R_905_10586@l' => array(
'label' => __('Moms udgør:','woocommerce'),'value' => $@R_905_10586@l_tax_amount
) );
$@R_905_10586@l_rows['order_@R_905_10586@l']['value'] = wc_price( $gran_@R_905_10586@l );
return $@R_905_10586@l_rows + $tax_row;
}
我们将不胜感激任何帮助。
以下内容会将“企业”用户角色的自定义总税行更改为零:
add_filter( 'woocommerce_get_order_item_@R_905_10586@ls','insert_custom_line_order_item_@R_905_10586@ls',10,3 );
function insert_custom_line_order_item_@R_905_10586@ls( $@R_905_10586@l_rows,$order,$tax_display ){
$user = $order->get_user(); // Gets WP_User Object from order
$@R_905_10586@l = $order->get_@R_905_10586@l(); // Gets order grand @R_905_10586@l. incl. taxes
// Clean @R_905_10586@l row displayed taxes
$@R_905_10586@l_rows['order_@R_905_10586@l']['value'] = is_wc_endpoint_url() ? wc_price($@R_905_10586@l) : Strip_tags(wc_price($@R_905_10586@l));
// Get @R_905_10586@l tax formatted from a defined tax rate based on user roles
$@R_905_10586@l_tax = in_array('business',$user->roles) ? wc_price(0) : wc_price($@R_905_10586@l - ($@R_905_10586@l / 1.25));
// Insert @R_905_10586@l tax row
$@R_905_10586@l_rows['order_tax_@R_905_10586@l'] = array(
'label' => __('Moms udgør:','woocommerce'),'value' => is_wc_endpoint_url() ? $@R_905_10586@l_tax : Strip_tags($@R_905_10586@l_taX),);
return $@R_905_10586@l_rows;
}
它应该可以工作。
以上是大佬教程为你收集整理的根据 WooCommerce 订单中的用户角色显示自定义税收总行全部内容,希望文章能够帮你解决根据 WooCommerce 订单中的用户角色显示自定义税收总行所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。