Updated on August 20, 2018
In Genesis Slack‘s WooCommerce channel, a user asked:
Totally random question but does anyone know how to remove the “Select Options” button in WooCommerce Shop Main page?
woocommerce_loop_add_to_cart_link
filter hook can be used to remove the Select options buttons for each variable product.
Add the following in child theme’s functions.php:
// Remove "Select options" button from (variable) products on the main WooCommerce shop page. | |
add_filter( 'woocommerce_loop_add_to_cart_link', function( $product ) { | |
global $product; | |
if ( is_shop() && 'variable' === $product->product_type ) { | |
return ''; | |
} else { | |
sprintf( '<a href="%s" data-quantity="%s" class="%s" %s>%s</a>', | |
esc_url( $product->add_to_cart_url() ), | |
esc_attr( isset( $args['quantity'] ) ? $args['quantity'] : 1 ), | |
esc_attr( isset( $args['class'] ) ? $args['class'] : 'button' ), | |
isset( $args['attributes'] ) ? wc_implode_html_attributes( $args['attributes'] ) : '', | |
esc_html( $product->add_to_cart_text() ) | |
); | |
} | |
} ); |
Before:
After:
References:
woocommerce/templates/loop/add-to-cart.php via woocommerce/includes/wc-template-functions.php via woocommerce/includes/wc-template-hooks.php via Query Monitor.
Hi Sir,
I need your help currently I am using woocommerce on my website I need a shop page variation products select option to replace with add to cart button. Its possible or not.
Thanks
Gautam
Hi Sridhar. This code works, but i dont like remove “Select options” button. I will only change rel=”nofollow” to rel=”dofollow”.
This line here: return sprintf( ‘%s
What is the code for the functions.php?
Many thanks i like your work
Hey, after using your code, all my variable value are gone. please help me to get them back
I have updated the code for the current latest WooCommerce.
You can give it a try.
If the problem persists, you may want to contact WooCommerce support.
Hi there
Wondering if this code still works? I have just implemented but it doesn’t seem to have made any changes?
Many thanks in advance.
Clojo