【问题标题】:Add a text to WooCommerce orders displayed total price向显示总价的 WooCommerce 订单添加文本
【发布时间】:2021-03-16 07:33:04
【问题描述】:

通过以下钩子,我将文本添加到总价格中:

add_filter( 'woocommerce_cart_totals_order_total_html', 'custom_total_message_html', 10, 1 );
function custom_total_message_html( $value ) {

        $text_to_add_before_price  = 'excl. BTW '; //change text in quotes to your preferred text 
  

    return $text_to_add_before_price . $value;
}

只有我在感谢页面上看到它没有显示在表格中。是否可以仅在“总计”行中为价格添加文本?​​

在示例中为:20.35 欧元,但这应该是 20.35 欧元,不包括在内。增值税。使用当前的钩子,这仅在购物车和结帐页面中完成

【问题讨论】:

    标签: php wordpress woocommerce hook-woocommerce orders


    【解决方案1】:

    对于订单(和电子邮件通知)使用以下命令在订单总行之前添加自定义文本:

    add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 1000, 3 );
    function custom_order_total_line_html( $total_rows, $order, $tax_display ){
        $total_rows['order_total']['value'] = __('excl. BTW ') . ' ' . $total_rows['order_total']['value'];
    
        return $total_rows;
    }
    

    代码位于活动子主题(或活动主题)的functions.php 文件中。经过测试并且可以工作。


    改为使用后添加:

    add_filter( 'woocommerce_get_order_item_totals', 'custom_order_total_line_html', 1000, 3 );
    function custom_order_total_line_html( $total_rows, $order, $tax_display ){
        $total_rows['order_total']['value'] .= ' ' . __('excl. BTW ');
    
        return $total_rows;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 2018-04-11
      • 1970-01-01
      • 2020-07-20
      • 2020-03-31
      • 1970-01-01
      相关资源
      最近更新 更多