【问题标题】:Remove subtotal line from orders pages, email notifications and cart + checkout pages in WooCommerce从 WooCommerce 中的订单页面、电子邮件通知和购物车 + 结帐页面中删除小计行
【发布时间】:2019-04-16 02:27:52
【问题描述】:

我想从购物车、结帐、收到的订单、订单详情和电子邮件中删除小计。我不想使用 CSS,因为它不会从订单详细信息页面和电子邮件中删除参考。我试过这段代码:

add_filter( 'woocommerce_get_order_item_totals', 'adjust_woocommerce_get_order_item_totals' );

function adjust_woocommerce_get_order_item_totals( $totals ) {
  unset($totals['cart_subtotal']  );
  return $totals;
}

它不起作用,小计在购物车和结帐页面上可见。

是否有任何其他功能,或者我是否必须在我的活动主题下创建一个单独的 woocommerce 文件夹并从模板中删除任何“小计”的引用。

【问题讨论】:

    标签: php templates woocommerce cart checkout


    【解决方案1】:

    1) 对于所有订单页面和电子邮件通知 (已收到订单、订单付款、订单查看和电子邮件)

    您的代码有效并从总计行中删除小计行:

    add_filter( 'woocommerce_get_order_item_totals', 'remove_subtotal_from_orders_total_lines', 100, 1 );
    function remove_subtotal_from_orders_total_lines( $totals ) {
        unset($totals['cart_subtotal']  );
        return $totals;
    }
    

    代码进入您的活动子主题(活动主题)的 function.php 文件中。经过测试并且可以工作。

    2) 对于购物车和结帐页面:

    以下模板需要to create a separate "woocommerce" folder under your active theme

    购物车 - cart/cart-totals.php |删除第 32 到 35 行的代码块:

    <tr class="cart-subtotal">
        <th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
        <td data-title="<?php esc_attr_e( 'Subtotal', 'woocommerce' ); ?>"><?php wc_cart_totals_subtotal_html(); ?></td>
    </tr>
    

    结帐 - checkout/review-order.php |删除第 58 到 61 行的代码块:

    <tr class="cart-subtotal">
        <th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
        <td><?php wc_cart_totals_subtotal_html(); ?></td>
    </tr>
    

    保存两个模板...你完成了。

    【讨论】:

      猜你喜欢
      • 2020-10-27
      • 1970-01-01
      • 2018-10-01
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 1970-01-01
      • 2020-04-08
      • 2018-01-24
      相关资源
      最近更新 更多