- This topic has 13 replies, 3 voices, and was last updated 15 hours, 13 minutes ago by
Tom.
-
AuthorPosts
-
April 8, 2021 at 1:25 am #1725806
tertas
Hello,
Sticky add to cart works well on simple products.
But doesn’t work for composite products.
https://woocommerce.com/products/composite-products/Any advice to make it work?
April 8, 2021 at 3:40 am #1725979David
StaffCustomer SupportHi there,
the sticky add to cart only works with the default product types in woocommerce.
In GPP 2.0 which should be released within a week or so you will be able to filter what product types it works with …. Tom provides the filter here:Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/April 8, 2021 at 6:19 am #1726147tertas
Hi David,
I updated to GPP 2.0 beta.
Add this code as snippet. But didn’t work.
add_filter( 'generate_wc_sticky_add_to_cart_action', function( $action, $product ) { if ( $product->is_type( 'composite' ) ) { $quantity_buttons = ''; if ( generatepress_wc_get_setting( 'quantity_buttons' ) ) { $quantity_buttons = ' do-quantity-buttons'; } $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() ) ); } return $action; }, 10, 2 );
April 8, 2021 at 8:21 am #1726530Tom
Lead DeveloperLead DeveloperStrange, that looks good to me.
Anything show if you do this?:
add_filter( 'generate_wc_sticky_add_to_cart_action', function( $action, $product ) { var_dump($product->is_type( 'composite' )); return $action; }, 10, 2 );
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 8, 2021 at 8:30 am #1726538tertas
Hi Tom,
I added both nothing happened.
I deleted old one added new one, nothing happened.You can check yourself.
April 9, 2021 at 2:14 am #1727291tertas
Hi Tom,
Our developer managed to show sticky bar with this filter.
generate_wc_show_sticky_add_to_cartBut we still can’t see the QTY and Price areas in sticky bar.
I have put their codes in below.
April 9, 2021 at 8:26 am #1727889Tom
Lead DeveloperLead DeveloperAlong with the filter your dev used, can you try this again?: https://generatepress.com/forums/topic/sticky-add-to-cart-at-composite-products/#post-1726530
Anything show up?
Also, please share code in the regular reply field – that way we can edit it/format it if necessary π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 9, 2021 at 9:02 am #1727931tertas
Hi Tom,
Sure, When I add below CSS + developers’ code I see this. https://prnt.sc/118bpwn
add_filter( 'generate_wc_sticky_add_to_cart_action', function( $action, $product ) { var_dump($product->is_type( 'composite' )); return $action; }, 10, 2 );
If I use developer’s code + below CSS, I see this. https://prnt.sc/118brhf
add_filter( 'generate_wc_sticky_add_to_cart_action', function( $action, $product ) { var_dump($product->is_type( 'composite' )); return $action; }, 10, 2 ); add_filter( 'generate_wc_sticky_add_to_cart_action', function( $action, $product ) { if ( $product->is_type( 'composite' ) ) { $quantity_buttons = ''; if ( generatepress_wc_get_setting( 'quantity_buttons' ) ) { $quantity_buttons = ' do-quantity-buttons'; } $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() ) ); } return $action; }, 10, 2 );
Also Here is developer’s code. He didn’t use below part due to error.
add_filter('generate_wc_show_sticky_add_to_cart', function ($show){ $product = wc_get_product( get_the_ID() ); if($product->is_type( 'composite' )) $show = true; return $show; }, 10, 1); /** add_filter('generate_wc_sticky_add_to_cart_action', function ($action, $product){ if($product->is_type('composite')) { if ( generatepress_wc_get_setting( 'quantity_buttons' ) ) { $quantity_buttons = ' do-quantity-buttons'; } $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() ) ); } return $action; }, 10, 2); */
April 9, 2021 at 9:16 am #1727947tertas
If I use only below codes together, result is better. https://prnt.sc/118c29p
It says “See Details” on the button but actually it adds the product to cart. π1. Can we use “add to cart” wording in there?
2. It adds only 1pcs, even I choose 5pcs.add_filter('generate_wc_show_sticky_add_to_cart', function ($show){ $product = wc_get_product( get_the_ID() ); if($product->is_type( 'composite' )) $show = true; return $show; }, 10, 1); add_filter('generate_wc_sticky_add_to_cart_action', function ($action, $product){ if($product->is_type('composite')) { if ( generatepress_wc_get_setting( 'quantity_buttons' ) ) { $quantity_buttons = ' do-quantity-buttons'; } $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() ) ); } return $action; }, 10, 2);
April 10, 2021 at 9:44 am #1729001Tom
Lead DeveloperLead Developer1. You can replace the follow code with your desired Add to Cart text:
esc_html( $product->add_to_cart_text() )
So that would become:
'Add to Cart'
2. Try removing this:
if ( generatepress_wc_get_setting( 'quantity_buttons' ) ) { $quantity_buttons = ' do-quantity-buttons'; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 10, 2021 at 1:34 pm #1729197tertas
Hello Tom,
Thanks for the advice.
1. Solved.
2. If I remove that code, QTY button looks weird. https://prnt.sc/119798x
2b. Even removed above code, qty problem exist. I choose 5pcs but it adds 1pcs to cart.
3. I just realize that price doesn’t seen in the stick bar.Thank you.
Here is the latest version of the code;
add_filter('generate_wc_show_sticky_add_to_cart', function ($show){ $product = wc_get_product( get_the_ID() ); if($product->is_type( 'composite' )) $show = true; return $show; }, 10, 1); add_filter('generate_wc_sticky_add_to_cart_action', function ($action, $product){ if($product->is_type('composite')) { // if ( generatepress_wc_get_setting( 'quantity_buttons' ) ) { // $quantity_buttons = 'do-quantity-buttons'; //} $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() ) 'Sepete Ekle', ); } return $action; }, 10, 2);
April 11, 2021 at 9:21 am #1730074Tom
Lead DeveloperLead DeveloperSo the issue seems to be related to the product type itself, as even manually entering a quantity into the quantity input doesn’t work – it always adds 1 as the quantity.
I’m not sure why it would be doing that – you can test the default functionality here: https://gpsites.co/merch/product/happy-ninja-hoodie/
It may be something your developer needs to debug step by step directly on the server, as I’m not familiar with the plugin/product type you’re using and what kind of changes it makes to WooCommerce.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 11, 2021 at 9:27 am #1730078tertas
Hi Tom,
It is definitely related with composite product.
Simple products are working very well in same website.We will continue to try. If we find anything we will let you know.
Same developer managed to fix it for another theme, which I am trying to get rid of now.April 12, 2021 at 7:45 am #1731338Tom
Lead DeveloperLead DeveloperSounds good – I’m interested to hear what the problem is.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.