Skip to content

Instantly share code, notes, and snippets.

@srikat
Last active October 13, 2019 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srikat/c98bb6e2bafdba19a3f43cee5c3ad7ac to your computer and use it in GitHub Desktop.
Save srikat/c98bb6e2bafdba19a3f43cee5c3ad7ac to your computer and use it in GitHub Desktop.
Remove "Select options" button from (variable) products on the main WooCommerce shop page. https://sridharkatakam.com/remove-select-options-button-variable-products-main-woocommerce-shop-page/
// 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() )
);
}
} );
@chr0n0are
Copy link

Hi,

Found this thru Google :)

I tried this code but did not work, really frustrating that they don´t have the option to just show the price and name+picture of the product when you have variable products.

@srikat
Copy link
Author

srikat commented Aug 20, 2018

Updated based on the current latest WooCommerce as of today, 3.4.4.

@CamiloB
Copy link

CamiloB commented Sep 13, 2018

hi this code go in functions.php ?

@thetwopct
Copy link

Found through Google - seems to be giving me an error:

Notice: product_type was called incorrectly. Product properties should not be accessed directly. Backtrace: require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/XXXX/woocommerce/archive-product.php'), wc_get_template_part, load_template, require('/plugins/woocommerce/templates/content-product.php'), do_action('woocommerce_after_shop_loop_item'), WP_Hook->do_action, WP_Hook->apply_filters, call_user_func_array, woocommerce_template_loop_add_to_cart, wc_get_template, include('/plugins/woocommerce/templates/loop/add-to-cart.php'), apply_filters('woocommerce_loop_add_to_cart_link'), WP_Hook->apply_filters, call_user_func_array, {closure}, WC_Abstract_Legacy_Product->__get, wc_doing_it_wrong
Please see Debugging in WordPress for more information. (This message was added in version 3.0.) in home/XXXX/public_html/wp-includes/functions.php on line 4169

@thetwopct
Copy link

Fixed it with:

//
// Remove "Select options" button from (variable) products on main WooCommerce shop page
add_filter( 'woocommerce_loop_add_to_cart_link', function( $product ) {

	global $product;

	if ( is_shop() && $product->is_type( 'variable' )) {
		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() )
		);
	}
} );

@KingCodeST
Copy link

thank you it worked great @thetwopct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment