diff --git a/cgkit-floating-cart.php b/cgkit-floating-cart.php index b85bcea..253ca9b 100644 --- a/cgkit-floating-cart.php +++ b/cgkit-floating-cart.php @@ -3,7 +3,7 @@ * Plugin Name: CommerceKit Floating Cart * Plugin URI: https://www.commercegurus.com * Description: Adds a floating cart icon (bottom-right) and auto-opens the CommerceKit minicart after add to cart. Requires CommerceGurus CommerceKit and WooCommerce. - * Version: 1.0.3 + * Version: 1.0.4 * Author: CommerceGurus * Author URI: https://www.commercegurus.com * License: GPLv3 @@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } -define( 'CGKIT_FC_VERSION', '1.0.3' ); +define( 'CGKIT_FC_VERSION', '1.0.4' ); define( 'CGKIT_FC_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); define( 'CGKIT_FC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); @@ -58,6 +58,37 @@ class CommerceKit_Floating_Cart { // Ensure WooCommerce's AJAX add-to-cart is active so the body receives // the `added_to_cart` JS event that our script listens for. add_filter( 'pre_option_woocommerce_enable_ajax_add_to_cart', [ $this, 'enable_ajax_add_to_cart' ] ); + + // Show the CommerceKit free shipping notification for guests. + // WC's show_shipping() returns false for logged-out users when the store + // hides shipping costs until an address is entered, which causes CommerceKit + // to skip rendering the bar entirely. We force shipping => true for any + // non-empty cart so the notification always renders. + add_filter( 'commercekit_fsn_get_cart_options', [ $this, 'fsn_show_for_guests' ] ); + } + + /** + * Force the CommerceKit free shipping notification to render for logged-out + * users. WC_Cart::show_shipping() returns false for guests when the store + * option "Hide shipping costs until an address is entered" is active, which + * makes CommerceKit bail before building the bar HTML. Overriding the + * `shipping` key here only affects the FSN display logic — WooCommerce's + * actual shipping calculation is untouched. + * + * @param array $options Result from commercekit_fsn_get_cart_options(). + * @return array + */ + public function fsn_show_for_guests( array $options ): array { + if ( ! isset( $options['shipping'] ) || $options['shipping'] ) { + return $options; // already showing, nothing to do. + } + + $cart = WC()->cart; + if ( $cart && $cart->get_cart_contents_count() > 0 && $options['amount'] > 0 ) { + $options['shipping'] = true; + } + + return $options; } /**