-
rtmslu
Hi!
I’m having trouble getting the sticky cart panel display on simple subscription products. How to resolve this?
-
George
Hello,
Sticky cart panel is not a GP feature. Are you using a plugin for subscription products? Can you please clarify and provide a link?
-
rtmslu
Hi, George
To my knowledge sticky cart panel is GP premium feature which was added with ver 1.8 https://generatepress.com/gp-premium-1-8/
I use Woo Subscriptions plugin. With regular products when on product page (mobile/desktop) when scrolling down the page and past add to cart button a sticky add to cart panel appears on top of page on desktop and bottom of page on mobile. With simple subscription products it does not appear.
WordPress version: 7.0.2
WooCommerce version: 10.9.4
GP Premium version: 3.6.1 -
George
Hello,
Could you point me to a simple subscription product on your website, please?
-
rtmslu
I added the link under private information.
-
George
Hi,
I can see the issue. Is it possible to have access to that staging site? You can also install the Temporary Login Without Password plugin and send us a login link without using a password. Please, use the private area of your reply to send those details.
-
rtmslu
I added the link
-
George
Hi,
The sticky cart panel is limited to simple and variable products, so it doesn’t show on subscription products by default. You can extend it to subscription products with this snippet:
add_filter( 'generate_wc_show_sticky_add_to_cart', function( $show ) { if ( ! function_exists( 'wc_get_product' ) || ! is_singular( 'product' ) ) { return $show; } $product = wc_get_product( get_the_ID() ); if ( $product && ( $product->is_type( 'subscription' ) || $product->is_type( 'variable-subscription' ) ) && $product->is_purchasable() && $product->is_in_stock() ) { $show = true; } return $show; } );You can add it to your child theme’s functions.php or through a snippet plugin.
-
rtmslu
Thank you, George
It works, meaning sticky panel appears, however the Add-to-cart and quantity buttons are missing.
-
George
Hello,
Can you replace the previous code with this one, please?
// Enable the sticky add to cart panel for subscription products. add_filter( 'generate_wc_show_sticky_add_to_cart', function( $show ) { if ( ! function_exists( 'wc_get_product' ) || ! is_singular( 'product' ) ) { return $show; } $product = wc_get_product( get_the_ID() ); if ( $product && ( $product->is_type( 'subscription' ) || $product->is_type( 'variable-subscription' ) ) && $product->is_purchasable() && $product->is_in_stock() ) { $show = true; } return $show; } ); // Output the add to cart form/button in the panel for subscription products. add_filter( 'generate_wc_sticky_add_to_cart_action', function( $action, $product ) { if ( ! $product ) { return $action; } $quantity_buttons = generatepress_wc_get_setting( 'quantity_buttons' ) ? ' do-quantity-buttons' : ''; if ( $product->is_type( 'subscription' ) ) { $args = array( 'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ), 'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ), ); $action = sprintf( '<form action="%1$s" class="cart%2$s" method="post" enctype="multipart/form-data">%3$s<button type="submit" class="button alt">%4$s</button></form>', esc_url( $product->add_to_cart_url() ), $quantity_buttons, woocommerce_quantity_input( $args, $product, false ), esc_html( $product->add_to_cart_text() ) ); } if ( $product->is_type( 'variable-subscription' ) ) { $action = sprintf( '<button type="submit" class="button alt go-to-variables">%s</button>', esc_html( $product->add_to_cart_text() ) ); } return $action; }, 10, 2 ); -
rtmslu
I replaced it.
Awesome, it works and looks good!
Big thanks, George!
-
George
Ok, no problem!
- You must be logged in to reply to this topic.