Introduce woocommerce_widget_shopping_cart_subtotal function and move minicart template subtotal to use it. New woocommerce_before_cart_collaterals, woocommerce_widget_shopping_cart_total and woocommerce_widget_shopping_cart_after_buttons actions for making the cart and mini cart templates more flexible without having to override it.
This commit is contained in:
parent
60b385ea93
commit
6e4e818170
|
@ -2083,6 +2083,17 @@ if ( ! function_exists( 'woocommerce_widget_shopping_cart_proceed_to_checkout' )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( ! function_exists( 'woocommerce_widget_shopping_cart_subtotal' ) ) {
|
||||||
|
/**
|
||||||
|
* Output to view cart subtotal.
|
||||||
|
*
|
||||||
|
* @since 3.7.0
|
||||||
|
*/
|
||||||
|
function woocommerce_widget_shopping_cart_subtotal() {
|
||||||
|
echo '<strong>' . esc_html( 'Subtotal', 'woocommerce' ) . ':</strong> ' . WC()->cart->get_cart_subtotal(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Mini-Cart */
|
/** Mini-Cart */
|
||||||
|
|
||||||
if ( ! function_exists( 'woocommerce_mini_cart' ) ) {
|
if ( ! function_exists( 'woocommerce_mini_cart' ) ) {
|
||||||
|
|
|
@ -220,6 +220,7 @@ add_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_condition
|
||||||
*/
|
*/
|
||||||
add_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
|
add_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_button_view_cart', 10 );
|
||||||
add_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
|
add_action( 'woocommerce_widget_shopping_cart_buttons', 'woocommerce_widget_shopping_cart_proceed_to_checkout', 20 );
|
||||||
|
add_action( 'woocommerce_widget_shopping_cart_total', 'woocommerce_widget_shopping_cart_subtotal', 10 );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cart.
|
* Cart.
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 3.5.0
|
* @version 3.7.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
@ -48,13 +48,17 @@ do_action( 'woocommerce_before_cart' ); ?>
|
||||||
|
|
||||||
<td class="product-remove">
|
<td class="product-remove">
|
||||||
<?php
|
<?php
|
||||||
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf(
|
echo apply_filters( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||||
'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>',
|
'woocommerce_cart_item_remove_link',
|
||||||
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
|
sprintf(
|
||||||
esc_html__( 'Remove this item', 'woocommerce' ),
|
'<a href="%s" class="remove" aria-label="%s" data-product_id="%s" data-product_sku="%s">×</a>',
|
||||||
esc_attr( $product_id ),
|
esc_url( wc_get_cart_remove_url( $cart_item_key ) ),
|
||||||
esc_attr( $_product->get_sku() )
|
esc_html__( 'Remove this item', 'woocommerce' ),
|
||||||
), $cart_item_key );
|
esc_attr( $product_id ),
|
||||||
|
esc_attr( $_product->get_sku() )
|
||||||
|
),
|
||||||
|
$cart_item_key
|
||||||
|
);
|
||||||
?>
|
?>
|
||||||
</td>
|
</td>
|
||||||
|
|
||||||
|
@ -101,13 +105,17 @@ do_action( 'woocommerce_before_cart' ); ?>
|
||||||
if ( $_product->is_sold_individually() ) {
|
if ( $_product->is_sold_individually() ) {
|
||||||
$product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
|
$product_quantity = sprintf( '1 <input type="hidden" name="cart[%s][qty]" value="1" />', $cart_item_key );
|
||||||
} else {
|
} else {
|
||||||
$product_quantity = woocommerce_quantity_input( array(
|
$product_quantity = woocommerce_quantity_input(
|
||||||
'input_name' => "cart[{$cart_item_key}][qty]",
|
array(
|
||||||
'input_value' => $cart_item['quantity'],
|
'input_name' => "cart[{$cart_item_key}][qty]",
|
||||||
'max_value' => $_product->get_max_purchase_quantity(),
|
'input_value' => $cart_item['quantity'],
|
||||||
'min_value' => '0',
|
'max_value' => $_product->get_max_purchase_quantity(),
|
||||||
'product_name' => $_product->get_name(),
|
'min_value' => '0',
|
||||||
), $_product, false );
|
'product_name' => $_product->get_name(),
|
||||||
|
),
|
||||||
|
$_product,
|
||||||
|
false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); // PHPCS: XSS ok.
|
echo apply_filters( 'woocommerce_cart_item_quantity', $product_quantity, $cart_item_key, $cart_item ); // PHPCS: XSS ok.
|
||||||
|
@ -151,6 +159,8 @@ do_action( 'woocommerce_before_cart' ); ?>
|
||||||
<?php do_action( 'woocommerce_after_cart_table' ); ?>
|
<?php do_action( 'woocommerce_after_cart_table' ); ?>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<?php do_action( 'woocommerce_before_cart_collaterals' ); ?>
|
||||||
|
|
||||||
<div class="cart-collaterals">
|
<div class="cart-collaterals">
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
*
|
*
|
||||||
* @see https://docs.woocommerce.com/document/template-structure/
|
* @see https://docs.woocommerce.com/document/template-structure/
|
||||||
* @package WooCommerce/Templates
|
* @package WooCommerce/Templates
|
||||||
* @version 3.5.0
|
* @version 3.7.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
defined( 'ABSPATH' ) || exit;
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
@ -70,12 +70,23 @@ do_action( 'woocommerce_before_mini_cart' ); ?>
|
||||||
?>
|
?>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<p class="woocommerce-mini-cart__total total"><strong><?php esc_html_e( 'Subtotal', 'woocommerce' ); ?>:</strong> <?php echo WC()->cart->get_cart_subtotal(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></p>
|
<p class="woocommerce-mini-cart__total total">
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Woocommerce_widget_shopping_cart_total hook.
|
||||||
|
*
|
||||||
|
* @hooked woocommerce_widget_shopping_cart_subtotal - 10
|
||||||
|
*/
|
||||||
|
do_action( 'woocommerce_widget_shopping_cart_total' );
|
||||||
|
?>
|
||||||
|
</p>
|
||||||
|
|
||||||
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
|
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
|
||||||
|
|
||||||
<p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
|
<p class="woocommerce-mini-cart__buttons buttons"><?php do_action( 'woocommerce_widget_shopping_cart_buttons' ); ?></p>
|
||||||
|
|
||||||
|
<?php do_action( 'woocommerce_widget_shopping_cart_after_buttons' ); ?>
|
||||||
|
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
|
||||||
<p class="woocommerce-mini-cart__empty-message"><?php esc_html_e( 'No products in the cart.', 'woocommerce' ); ?></p>
|
<p class="woocommerce-mini-cart__empty-message"><?php esc_html_e( 'No products in the cart.', 'woocommerce' ); ?></p>
|
||||||
|
|
Loading…
Reference in New Issue