Last active
March 13, 2018 09:41
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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