Last active
July 22, 2024 03:35
-
-
Save braddalton/e51ad89b76a3274c7c4d9e385fd89eb4 to your computer and use it in GitHub Desktop.
Remove quantity field when a product can only be sold individually WooCommerce https://wpsites.net/wordpress-tutorials/remove-quantity-field-when-a-product-can-only-be-sold-individually-woocommerce/
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
function remove_quantity_field_for_sold_individually_products() { | |
if ( is_product() ) { | |
global $product; | |
if ( is_object( $product ) && $product->is_sold_individually() ) { | |
// Remove the quantity field | |
remove_action( 'woocommerce_before_add_to_cart_quantity', 'woocommerce_template_single_add_to_cart', 10 ); | |
remove_action( 'woocommerce_after_add_to_cart_quantity', 'woocommerce_template_single_add_to_cart', 10 ); | |
} | |
} | |
} | |
add_action( 'wp', 'remove_quantity_field_for_sold_individually_products' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment