skip to Main Content

I’d love to be able to use the “Sold individually” toggle and keep things simple… But I have a Name Your Price plugin going, and the price can only be edited before the ‘Add to Cart’ button is hit. If someone changes their mind and wants to enter a different price after that, I’d rather they could just do it there, and then delete the old price at the Cart stage (rather than having to go into Cart and delete it first, then come back and go again… yeah).

So, I’m fine with all the quantity fields being gone or locked (the product is a digital download), but the prevention of multiple additions to cart is a problem in this case. Needless to say, quantity field hiding fixes using ‘woocommerce_is_sold_individually’ are out.

I’ve also seen things of this style suggested online, but haven’t got any of them to work:

    add_action( 'wp_head', 'quantity_wp_head' );
function quantity_wp_head() {
if ( is_product() ) {
    ?>
<style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>

Does anyone have a better solution?

2

Answers


  1. Chosen as BEST ANSWER

    Thanks to the nudge from Redec, I found a solution that works for my case!

    Adding one of the following to my child theme's style.css for each page where a single product/single product shortcode is displayed removes the quantity field at the 'Add to Cart' stage, but still lets the user add multiple copies of a product to Cart if they so choose (if they change their mind about their nominated price after hitting Add to Cart and submit again), AND tidy up any errors (such as adding the same price twice) at the cart stage.

    (Not specifying the page ID removes the quantity field from the Cart page too and prevents that last bit, so the extra bit of fiddle is worth it imo. The Reveal IDs plugin makes this less of a pain https://wordpress.org/plugins/reveal-ids-for-wp-admin-25/)

    .page-id-12247 .woocommerce .quantity .qty {
        Display:None!important;
    }
    

    Happy to have a simple answer for my odd case!


  2. You can normally achieve hiding fields through CSS something like

    .quantity-box{
    
    Display:None!important;
    
    }
    

    To find the class or the name right click on the field and press inspect

    Class will begin with a full stop for example .Class

    A Name will begin with a hashtag as follows #Name

    Hope this helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search