Hello,
You can achieve this by multiple ways, here i am sharing ( i am explaining the case on the basis of product, you can modify it as per your needs) :
1. Using CSS:
add_action( 'wp_head', 'ced_quantity_wp_head' );
function ced_quantity_wp_head() {
if ( is_product() ) {
?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
<?php
}
}
2. Using WP Filter:
add_filter( 'woocommerce_is_sold_individually', 'ced_remove_quantity_fields', 10, 2 );
function ced_remove_quantity_fields( $return, $product ) {
// our conditions here
}
3. Using Option Sold Individually in Edit Product Page
=> Choose product where you don’t wish to show quantity field
=> Edit Product
=> From Bottom Click Inventory
=> Check the box Sold Individually
=> Update Product
If still issue let me know.
Thanks,
Hello and thanks for your reaction.
Option 1 I tried it
add_action( 'wp_head', 'ced_quantity_wp_head' );
function ced_quantity_wp_head()
{
if ( is_product_category( array ('glaswol', 'steenwol' ) ) )
{
?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
<?php
}
}
Option 2 is not clear for my what i need to put in the condions. And i think it wil work on products, not on categories.
Option 3 is taking me to long to make the changes, also for in the future.
Correct my if i’m wrong…
Roy
-
This reply was modified 6 years, 2 months ago by
dpcindexs.
Hello,
In first case, in place of is_product, you can use
is_category() and then it will work on category page.
In second case, we are getting the whole object of product, in $product. We can easily get the category of the product and then we can match the category using if conditions, and then return true.have a look on the basis of product type.
$pro_type = $product->product_type;
if( $pro_type == “variable” ) {
return true;
}
if( $pro_type == “external” ){
return true;
}
and so on
Thanks,
I tried is_category() and with is_product_category() with option 1. But i’m not doing it right because nothing happens. If i use is_product() it works, but then it works on all products.
add_action( 'wp_head', 'ced_quantity_wp_head' );
function ced_quantity_wp_head()
{
if ( is_category('steenwol' ) )
{
?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
<?php
}
}
Can you give me a example where you use the category for option 1 or 2?
-
This reply was modified 6 years, 2 months ago by
dpcindexs.
Hi there,
Please try changing the code to the following (replace ‘cat1’, ‘cat2’ etc with the slugs of your product categories):
add_action( 'wp_head', 'ced_quantity_wp_head' );
function ced_quantity_wp_head()
{
if (has_term( array( 'cat1', 'cat2', 'cat3' ), 'product_cat' ))
{
?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
<?php
}
}
I hope that helps! Have a wonderful day!
Hi there,
We haven’t heard back from you in a while, so I’m going to mark this thread as resolved. If you have any further questions, please start a new thread.
Have a wonderful day!