根据WooCommerce订单中的用户角色显示自定义税收总计行

我正在WooCommerce中建立一个网上商店,我需要在订单电子邮件中显示正确的税款。我有2种不同的用户角色:“私人”和“企业”

以下代码进行税额计算并将其添加到新行中。但是,对于“企业”用户角色,我需要输出为0DKK (因为他们支付的价格是不含税的)

// Add total taxes as a separated line before order total on orders and emails
add_filter( 'woocommerce_get_order_item_totals', 'insert_custom_line_order_item_totals', 10, 3 );
function insert_custom_line_order_item_totals( $total_rows, $order, $tax_display ){
    // Display only the gran total amount
    $gran_total = (float) $order->get_total();
    $total_rows['order_total']['value'] = is_wc_endpoint_url() ? $total_html : strip_tags( $total_html );

    // Custom tax calculation (for 20% tax rate)
    $total_tax_amount = wc_price(  $gran_total - $gran_total / 1.25 );
    $total_tax_amount = is_wc_endpoint_url() ? $total_tax_amount : strip_tags( $total_tax_amount );

    // Create a new row for total tax
    $tax_row = array( 'order_tax_total' => array(
        'label' => __('Moms udgør:','woocommerce'),
        'value' => $total_tax_amount
    ) );

    $total_rows['order_total']['value'] = wc_price( $gran_total );

    return $total_rows + $tax_row;
}

任何帮助将不胜感激。

LoicTheAztec

以下内容将针对“企业”用户角色的自定义总税款行更改为零:

add_filter( 'woocommerce_get_order_item_totals', 'insert_custom_line_order_item_totals', 10, 3 );
function insert_custom_line_order_item_totals( $total_rows, $order, $tax_display ){
    $user  = $order->get_user(); // Gets WP_User Object from order
    $total = $order->get_total(); // Gets order grand total. incl. taxes

    // Clean total row displayed taxes
    $total_rows['order_total']['value'] = is_wc_endpoint_url() ? wc_price($total) : strip_tags(wc_price($total));

    // Get total tax formatted from a defined tax rate based on user roles
    $total_tax = in_array('business', $user->roles) ? wc_price(0) : wc_price($total - ($total / 1.25));

    // Insert total tax row
    $total_rows['order_tax_total'] = array(
        'label' => __('Moms udgør:','woocommerce'),
        'value' => is_wc_endpoint_url() ? $total_tax : strip_tags($total_tax),
    );

    return $total_rows;
}

它应该工作。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

根据用户角色在WooCommerce购物车上显示自定义定价标签

来自分类Dev

根据Woocommerce中的用户角色自定义客户新帐户邮件

来自分类Dev

WooCommerce订单页面添加客户角色自定义列

来自分类Dev

如何在WooCommerce订单中显示产品自定义字段(自定义SKU)

来自分类Dev

WooCommerce中的自定义订单操作

来自分类Dev

在WooCommerce订单列表中显示Dokan自定义订单元数据

来自分类Dev

仅在WooCommerce Admin单个订单的手动订单中显示产品自定义字段

来自分类Dev

在WooCommerce订单管理员列表上显示带有自定义用户元的自定义列

来自分类Dev

根据woocommerce中的自定义订单状态触发短信发送

来自分类Dev

根据 WooCommerce 中的运输方式自定义订单接收页面

来自分类Dev

获取用户自定义元数据值并在WooCommerce订单中对其进行更新

来自分类Dev

在Woocommerce查看订单页面上显示自定义字段

来自分类Dev

订单自定义字段未显示在WooCommerce电子邮件通知中

来自分类Dev

保存结帐自定义字段值并将其显示在WooCommerce管理订单中

来自分类Dev

仅在WooCommerce Admin单笔订单中显示产品自定义字段

来自分类Dev

在woocommerce订单电子邮件中显示多个产品的自定义字段

来自分类Dev

基于用户角色或WooCommerce中的自定义数据的额外购物车费用

来自分类Dev

WooCommerce-在“谢谢”订单接收页面上自定义“总计”文本

来自分类Dev

自定义WooCommerce订单表中的总行

来自分类Dev

在 Woocommerce 订单总计行中添加计算的节省总计

来自分类Dev

仅在WooCommerce管理订单上显示自定义订单项目元数据

来自分类Dev

Woocommerce 新订单自定义主题

来自分类Dev

如何在woocommerce中的新订单电子邮件中显示高级自定义字段数据

来自分类Dev

根据自定义订单返回结果

来自分类Dev

根据运送国家/地区在WooCommerce结帐中显示自定义消息

来自分类Dev

自定义WooCommerce datepicker检出字段已保存并显示在订单和电子邮件中

来自分类Dev

在WooCommerce订单和电子邮件中添加和显示自定义购物车项目数据

来自分类Dev

如何在WooCommerce管理员单笔订单中显示自定义结帐账单字段

来自分类Dev

将自定义字段价格作为产品价格分配给WooCommerce中的特定用户角色

Related 相关文章

  1. 1

    根据用户角色在WooCommerce购物车上显示自定义定价标签

  2. 2

    根据Woocommerce中的用户角色自定义客户新帐户邮件

  3. 3

    WooCommerce订单页面添加客户角色自定义列

  4. 4

    如何在WooCommerce订单中显示产品自定义字段(自定义SKU)

  5. 5

    WooCommerce中的自定义订单操作

  6. 6

    在WooCommerce订单列表中显示Dokan自定义订单元数据

  7. 7

    仅在WooCommerce Admin单个订单的手动订单中显示产品自定义字段

  8. 8

    在WooCommerce订单管理员列表上显示带有自定义用户元的自定义列

  9. 9

    根据woocommerce中的自定义订单状态触发短信发送

  10. 10

    根据 WooCommerce 中的运输方式自定义订单接收页面

  11. 11

    获取用户自定义元数据值并在WooCommerce订单中对其进行更新

  12. 12

    在Woocommerce查看订单页面上显示自定义字段

  13. 13

    订单自定义字段未显示在WooCommerce电子邮件通知中

  14. 14

    保存结帐自定义字段值并将其显示在WooCommerce管理订单中

  15. 15

    仅在WooCommerce Admin单笔订单中显示产品自定义字段

  16. 16

    在woocommerce订单电子邮件中显示多个产品的自定义字段

  17. 17

    基于用户角色或WooCommerce中的自定义数据的额外购物车费用

  18. 18

    WooCommerce-在“谢谢”订单接收页面上自定义“总计”文本

  19. 19

    自定义WooCommerce订单表中的总行

  20. 20

    在 Woocommerce 订单总计行中添加计算的节省总计

  21. 21

    仅在WooCommerce管理订单上显示自定义订单项目元数据

  22. 22

    Woocommerce 新订单自定义主题

  23. 23

    如何在woocommerce中的新订单电子邮件中显示高级自定义字段数据

  24. 24

    根据自定义订单返回结果

  25. 25

    根据运送国家/地区在WooCommerce结帐中显示自定义消息

  26. 26

    自定义WooCommerce datepicker检出字段已保存并显示在订单和电子邮件中

  27. 27

    在WooCommerce订单和电子邮件中添加和显示自定义购物车项目数据

  28. 28

    如何在WooCommerce管理员单笔订单中显示自定义结帐账单字段

  29. 29

    将自定义字段价格作为产品价格分配给WooCommerce中的特定用户角色

热门标签

归档