fix: show free shipping notification for logged-out users via commercekit_fsn_get_cart_options filter
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
* Plugin Name: CommerceKit Floating Cart
|
* Plugin Name: CommerceKit Floating Cart
|
||||||
* Plugin URI: https://www.commercegurus.com
|
* 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.
|
* 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: CommerceGurus
|
||||||
* Author URI: https://www.commercegurus.com
|
* Author URI: https://www.commercegurus.com
|
||||||
* License: GPLv3
|
* License: GPLv3
|
||||||
@@ -19,7 +19,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
exit;
|
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_URL', plugin_dir_url( __FILE__ ) );
|
||||||
define( 'CGKIT_FC_PLUGIN_DIR', plugin_dir_path( __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
|
// Ensure WooCommerce's AJAX add-to-cart is active so the body receives
|
||||||
// the `added_to_cart` JS event that our script listens for.
|
// 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' ] );
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user