Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Last active March 13, 2018 09:41
Show Gist options
  • Save WillBrubaker/a44d620be7c0795b928c to your computer and use it in GitHub Desktop.
Save WillBrubaker/a44d620be7c0795b928c to your computer and use it in GitHub Desktop.
Add Quantity Input to the WooCommerce Shop Page (simple products only) Without A Template Override
add_action( 'woocommerce_before_shop_loop_item', 'beardedguy_add_quantity_input' );
function beardedguy_add_quantity_input() {
global $product;
$product_type = ( version_compare( WC_VERSION, '3.0', '<' ) ) ? $product->product_type : $product->get_type();
if ( 'simple' == $product_type ) {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );
} else {
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 10 );
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment