mirror of
https://gh.wpcy.net/https://github.com/mainwp/Code-Snippets-Functions.git
synced 2026-05-01 11:52:25 +08:00
https://stackoverflow.com/questions/77113049/remove-totals-section-from-woocommerce-cart-while-keeping-subtotal-line/77113420
29 lines
1,013 B
Text
29 lines
1,013 B
Text
add_action( 'woocommerce_cart_collaterals', 'keep_only_cart_subtotal', 9 );
|
|
function keep_only_cart_subtotal(){
|
|
// Remove cart totals block
|
|
remove_action( 'woocommerce_cart_collaterals', 'woocommerce_cart_totals', 10 );
|
|
|
|
// Add back Subtotal, "Proceed to checkout" button (and hooks)
|
|
printf('<div class="cart_totals%s">', ( WC()->customer->has_calculated_shipping() ) ? ' calculated_shipping' : '');
|
|
|
|
do_action( 'woocommerce_before_cart_totals' );
|
|
|
|
?>
|
|
<table cellspacing="0" class="shop_table shop_table_responsive">
|
|
<tr class="cart-subtotal">
|
|
<th><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?></th>
|
|
<td data-title="<?php esc_attr_e( 'Subtotal', 'woocommerce' ); ?>"><?php wc_cart_totals_subtotal_html(); ?></td>
|
|
</tr>
|
|
</table>
|
|
<?php
|
|
|
|
echo '<div class="wc-proceed-to-checkout">';
|
|
|
|
do_action( 'woocommerce_proceed_to_checkout' );
|
|
|
|
echo '</div>';
|
|
|
|
do_action( 'woocommerce_after_cart_totals' );
|
|
|
|
echo '</div><br clear="all">';
|
|
}
|