Ecommerce Shopify WordPress Discussion

Exclude "sold individually" products in WooCommerce

I'm using this small php snippet on my functions.php in order to add a small text before my product quantity field on the WooCommerce single product page: add_action( 'woocommerce_before_add_to_cart_quantity', 'wp_echo_qty_front_add_cart' ); function wp_echo_qty_front_add_cart() { echo '<div class="qty">Número de asistentes: </div>'; } Works as a charm, but I would like to exclude from this all the products that are using the WooCommerce native "Sold individually" option. Is there anyway to do exclude them just by adding something to functions.php?
You can use WC_Product::get_sold_individually(), which indicates whether a product is sold individually. So you get: function action_woocommerce_before_add_to_cart_quantity() { global $product; // Is a WC product if ( is_a( $product, 'WC_Product' ) ) { // NOT sold individually. if ( ! $product->get_sold_individually() ) { echo '<div class="qty">Número de asistentes: </div>'; } } } add_action( 'woocommerce_before_add_to_cart_quantity', 'action_woocommerce_before_add_to_cart_quantity' );

January 7, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.