0

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?

darkcaldera
  • 31
  • 2
  • 6

2 Answers2

1

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!

darkcaldera
  • 31
  • 2
  • 6
0

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

RISL2023
  • 117
  • 8
  • Found the class, (.woocommerce .quantity .qty) and using Display:None!important in the style.css of my child theme seems to work. Discovered an issue with this where if you add the same product at the exact same price twice, there's no way to get rid of only one in cart (should have seen that coming), so even though it's an outlying case, I'll try and get that CSS to only apply to relevant pages (not Cart) to fix that. Progress, though, ta! – darkcaldera Mar 31 '20 at 03:20
  • @darkcaldera glad i could assist you in what you needed to do :) – RISL2023 Mar 31 '20 at 06:35