如何在WooCommerce购物车及结账页面移除订单总计模块
Got it, I totally get why you don’t want to rely on CSS—hiding elements with display:none just masks the section instead of actually removing it from the DOM, which can cause unexpected issues with WooCommerce’s backend logic or accessibility. Let’s use proper WooCommerce hooks to tackle this cleanly.
Step 1: Remove Totals from the Cart Page
The order totals section on the cart page is hooked into woocommerce_cart_collaterals by default with the callback woocommerce_cart_totals. We can unhook this to completely remove the section:
// Remove order totals from WooCommerce cart page add_action( 'init', 'remove_cart_order_totals' ); function remove_cart_order_totals() { remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 ); }
Step 2: Remove Totals from the Checkout Page
On the checkout page, the totals live in the order review section, hooked into woocommerce_checkout_order_review via woocommerce_checkout_totals. Here’s how to unhook that:
// Remove order totals from WooCommerce checkout page add_action( 'init', 'remove_checkout_order_totals' ); function remove_checkout_order_totals() { remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_totals', 10 ); }
Combine into a Single Function (Optional)
If you prefer to keep your code tidy, you can merge both removals into one function:
// Remove order totals from both cart and checkout pages add_action( 'init', 'remove_all_order_totals' ); function remove_all_order_totals() { // Cart page remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 ); // Checkout page remove_action( 'woocommerce_checkout_order_review', 'woocommerce_checkout_totals', 10 ); }
Important Notes
- Where to add this code: Paste it into your child theme’s
functions.phpfile, or use a custom code snippets plugin. Never edit WooCommerce core files—your changes will get overwritten when the plugin updates. - Adjust priority if needed: If your theme or another plugin has modified the hook priority (the
10in the code), you might need to match that number. You can check WooCommerce’s template files (likecart/cart-totals.phporcheckout/review-order.php) to confirm the priority being used.
内容的提问来源于stack exchange,提问作者Karan Rpn

