I have created some tabs using js and in each tab contains products from different categories. I have managed to modify add-to-cart link for simple products where ones the addtocart button is clicked it goes to the next tab without refreshing and the product is being added successfully to the cart.

if ( has_term( 'jeans-discount', 'product_cat', $post ) ) {
      echo apply_filters( 'woocommerce_loop_add_to_cart_link',
sprintf( '<a rel="nofollow" data-target="2" href="javascript:void(0); %s" data-quantity="%s" data-product_id="%s" data-product_sku="%s" class="custom %s">%s</a>',
    esc_url( $product->add_to_cart_url() ),
    esc_attr( isset( $quantity ) ? $quantity : 1 ),
    esc_attr( $product->get_id() ),
    esc_attr( $product->get_sku() ),
    esc_attr( isset( $class ) ? $class : 'button' ),
    esc_html( $product->add_to_cart_text() )
    $product );

However i am not able to modify the addtocart button for variable products in variation-add-to-cart.php.

<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>

For simple product the addtocart link shows as href=”javascript:void(0); /wordpress/woo-slider/?add-to-cart=73″
Is there a way i can do this for variable products addtocart link aswell

Read more here: Woocommerce custom add to cart button/link for variable products


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: