diff --git a/inc/plugins/woocommerce.php b/inc/plugins/woocommerce.php index 8183936..b12cd75 100644 --- a/inc/plugins/woocommerce.php +++ b/inc/plugins/woocommerce.php @@ -284,7 +284,7 @@ function stormbringer_handheld_footer_bar() { ), 'cart' => array( 'priority' => 30, - 'callback' => 'stormbringer_handheld_footer_bar_cart_link', + 'callback' => 'stormbringer_cart_items_number', ), ); @@ -333,24 +333,6 @@ function stormbringer_handheld_footer_bar_search() { } } -if ( ! function_exists( 'stormbringer_handheld_footer_bar_cart_link' ) ) { - /** - * The cart callback function for the handheld footer bar - * - * @since 2.0.0 - */ - function stormbringer_handheld_footer_bar_cart_link() { - ?> - - - cart->get_cart_contents_count() ); ?> - - '; } add_action('woocommerce_after_shop_loop_item', 'stormbringer_woocommerce_after_shop_loop_item', 999); -add_action('woocommerce_after_subcategory', 'stormbringer_woocommerce_after_shop_loop_item', 999); \ No newline at end of file +add_action('woocommerce_after_subcategory', 'stormbringer_woocommerce_after_shop_loop_item', 999); + +/** + * WooCommerce Cart Fragments + * Ensure cart contents update when products are added to the cart via AJAX + * + * @param array $fragments Fragments to refresh via AJAX. + * @return array Fragments to refresh via AJAX + */ +function stormbringer_cart_fragment( $fragments ) { + global $woocommerce; + + ob_start(); + stormbringer_cart_contents(); + $fragments['a.cart-contents'] = ob_get_clean(); + + ob_start(); + stormbringer_cart_items_number(); + $fragments['a.cart-items-number'] = ob_get_clean(); + + return $fragments; +} +add_filter( 'add_to_cart_fragments', 'stormbringer_cart_fragment' ); + + +/** + * WooCommerce Cart Link + * Displayed a link to the cart including the number of items present and the cart total + * + * @return void + * @since 1.0.0 + */ +function stormbringer_cart_items_number() { + ?> + + + cart->get_cart_contents_count() );?> + + + + cart->get_cart_subtotal() ); ?> cart->get_cart_contents_count(), 'storefront' ), WC()->cart->get_cart_contents_count() ) );?> + +