Skip to content

Instantly share code, notes, and snippets.

@braddalton
Last active July 22, 2024 03:35
Show Gist options
  • Save braddalton/e51ad89b76a3274c7c4d9e385fd89eb4 to your computer and use it in GitHub Desktop.
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/
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