• Resolved dpcindexs

    (@dpcindexs)


    Hello,

    I was wondering if it is possible to hide/remove the quantity input field based on the category. I can use below code for 1 product.

    .postid-7618 .input-text.qty.text
    {
    display: none;
    }

    I have over 200 products in 10 categories. I want to hide/remove the input of 8 categories and for 2 categories the input field needs to be vissible.

    If i use the above code, i need to put the postid line over 160 times in the css. A lot of work and a lot of clutter in my css…

    Thanks for the support!

    Roy

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • cedcommerce

    (@cedcommerce)

    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,

    Thread Starter dpcindexs

    (@dpcindexs)

    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 5 years ago by dpcindexs.
    cedcommerce

    (@cedcommerce)

    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,

    Thread Starter dpcindexs

    (@dpcindexs)

    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 5 years ago by dpcindexs.
    Plugin Support kellymetal a11n

    (@kellymetal)

    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!

    Plugin Support kellymetal a11n

    (@kellymetal)

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hide product quantity input field based on categories’ is closed to new replies.