• Resolved great2be

    (@great2be)


    Hello!

    I am trying to ad a AD TO CART BUTTON After original add to cart button. This new button would add three items to the cart.
    Everything works fine except I would like to filter it, that it will be shown only for product with id 282.

    The following code adds button to all products.
    Can you please assist me what am I doing wrong. Thanks!

    add_action( 'woocommerce_after_add_to_cart_button', 'additional_simple_add_to_cart', 3 );
    function additional_simple_add_to_cart() {
    
        global $product;
    
        if( ! $product->is_type('simple') && is_product_category( '282' ) ) return;
    
        $href = '?add-to-cart=' . esc_attr( $product->get_id() ) . '&quantity=3';
        $class = 'ingle_add_to_cart_button-12 button alt';
        $style = 'display: inline-block; margin-top: 12px;';
        $button_text = __( "Add to cart 3x product", "woocommerce" );
    
        // Output
        echo '<br><a rel="no-follow" href="'.$href.'" class="'.$class.'" style="'.$style.'">'.$button_text.'</a>';
       
    }
    • This topic was modified 5 years, 4 months ago by great2be.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi

    If you only want it for product ID 282 then why not just replace this

    if( ! $product->is_type('simple') && is_product_category( '282' ) ) return;

    with

    if ( !is_single( '282' ) ) return;

    Cheers!

    Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Howdy!

    We haven’t heard back from you in a while, so I’m going to go ahead and mark this thread as resolved. If you have any other questions please start a new thread.

    Cheers!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Additional Add to cart button’ is closed to new replies.