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; } /** * Return 'no' so WooCommerce never redirects to /cart after adding a product. */ public function disable_cart_redirect( string $value ): string { return 'no'; } /** * Return 'yes' so WooCommerce uses AJAX add-to-cart on archive/shop pages. * This ensures `added_to_cart` JS event fires without a page reload. */ public function enable_ajax_add_to_cart( string $value ): string { // Only override when it's not already enabled. return ( 'yes' === $value ) ? $value : 'yes'; } /** * Enqueue frontend CSS and JS. */ public function enqueue_assets(): void { wp_enqueue_style( 'cgkit-floating-cart', CGKIT_FC_PLUGIN_URL . 'assets/css/floating-cart.css', [], CGKIT_FC_VERSION ); wp_enqueue_script( 'cgkit-floating-cart', CGKIT_FC_PLUGIN_URL . 'assets/js/floating-cart.js', [ 'jquery' ], CGKIT_FC_VERSION, true ); /** * Filter: cgkit_fc_minicart_trigger * * CSS selector(s) for the theme's minicart open button. The floating * cart icon and the add-to-cart auto-open both programmatically click * the first matching element. * * For Shoptimizer / CommerceKit the default covers the most common * header cart selectors. Override this filter in your child theme if * needed. * * @param string $selector A comma-separated CSS selector string. */ $trigger = apply_filters( 'cgkit_fc_minicart_trigger', '.shoptimizer-cart .cart-contents, .site-header-cart .cart-contents, .wcmenucart, .header-cart-link' ); /** * Filter: cgkit_fc_auto_open * * Set to false to disable auto-opening the minicart after add to cart. * * @param bool $auto_open */ $auto_open = (bool) apply_filters( 'cgkit_fc_auto_open', true ); /** * Filter: cgkit_fc_auto_open_delay * * Milliseconds to wait before opening the minicart after add to cart, * to allow WooCommerce fragments to refresh first. * * @param int $delay */ $delay = (int) apply_filters( 'cgkit_fc_auto_open_delay', 400 ); wp_localize_script( 'cgkit-floating-cart', 'cgkitFC', [ 'minicartTrigger' => $trigger, 'autoOpen' => $auto_open ? 'yes' : 'no', 'autoOpenDelay' => $delay, 'cartUrl' => wc_get_cart_url(), ] ); } /** * Output the floating cart button HTML in the footer. */ public function render_floating_cart(): void { $count = WC()->cart ? WC()->cart->get_cart_contents_count() : 0; ?>