[Support request] Sticky add to cart at composite products

Home Forums Support Sticky add to cart at composite products

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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?

    #1725979
    David
    Staff
    Customer Support

    Hi 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:

    https://generatepress.com/forums/topic/add-to-cart-banner-not-showing-on-bundle-products/#post-1690182

    #1726147
    tertas

    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 );
    #1726530
    Tom
    Lead Developer
    Lead Developer

    Strange, 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 );
    #1726538
    tertas

    Hi Tom,

    I added both nothing happened.
    I deleted old one added new one, nothing happened.

    You can check yourself.

    #1727291
    tertas

    Hi Tom,

    Our developer managed to show sticky bar with this filter.
    generate_wc_show_sticky_add_to_cart

    But we still can’t see the QTY and Price areas in sticky bar.

    I have put their codes in below.

    #1727889
    Tom
    Lead Developer
    Lead Developer

    Along 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 πŸ™‚

    #1727931
    tertas

    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);
    */
    #1727947
    tertas

    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);
    #1729001
    Tom
    Lead Developer
    Lead Developer

    1. 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';
    }
    #1729197
    tertas

    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);
    #1730074
    Tom
    Lead Developer
    Lead Developer

    So 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.

    #1730078
    tertas

    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.

    #1731338
    Tom
    Lead Developer
    Lead Developer

    Sounds good – I’m interested to hear what the problem is.

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.