从Woocommerce中的购物车和结帐页面中删除小计行 [英] Remove subtotal line from cart and checkout pages in Woocommerce
问题描述
我想从购物车,结帐,收到的订单,订单明细和电子邮件中删除小计。我不想使用CSS,因为它不会从订单详细信息页面和电子邮件中删除引用。我已经尝试了以下代码:
I want to remove the Subtotals from Cart, Checkout, Order Received, Order Details and the emails. I don't want to use CSS, as it won't remove the reference from the order details page and emails. I have tried this code:
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;
}
此功能无效,小计在购物车和结帐页面上可见。
It isn't working, the Subtotal is visible on the Cart and Checkout pages.
还有其他功能吗?还是必须在活动主题下创建一个单独的woocommerce文件夹,然后从模板中删除小计的所有引用。
Is there any other function or do I have to create a separate woocommerce folder under my active theme and delete any reference of "Subtotal" from the templates.
推荐答案
1)对于所有订单页面和电子邮件通知 (已收到订单,订单付款,订单视图和电子邮件)
您的代码有效,并从总计行中删除了小计行:
Your code works and remove the subtotal line from totals lines:
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文件。经过测试并有效。
Code goes in function.php file of your active child theme (active theme). Tested and works.
2)对于购物车和结帐页面:
您需要在您的活动主题下为以下模板创建一个单独的 woocommerce文件夹:
购物车- cart / cart-totals.php
|从第32行到第35行删除代码块:
For cart - cart/cart-totals.php
| remove the code block from line 32 to 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:
For checkout - checkout/review-order.php
| remove the code block from line 58 to 61:
<tr class="cart-subtotal">
<th><?php _e( 'Subtotal', 'woocommerce' ); ?></th>
<td><?php wc_cart_totals_subtotal_html(); ?></td>
</tr>
保存两个模板...您已完成。
Save both templates… You are done.
这篇关于从Woocommerce中的购物车和结帐页面中删除小计行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!