Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

How can I hide the 'Quantity Select' field on a product page for specific variations?


TrueGreen

Question

Site URL: https://www.truegreencr.com/buy/p/product-la-macha

Similar to question How can I hide the 'Quantity Select' field on a product page?

But is it possible to customize this on a variant level as opposed to product level. For the example page I have this would be if I have 2 types, Sample and Product I want to disable quantity when a user clicks the Sample type from the dropdown. Is this possible via CSS?

Edited by TrueGreen
Link to post
  • Answers 1
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

1 answer to this question

Recommended Posts

  • 0
2 hours ago, TrueGreen said:

I want to disable quantity when a user clicks the Sample type from the dropdown. Is this possible via CSS?

Not with CSS alone.

However with a little Javascript and some CSS yes.

Add the following to Settings > Advanced > Code Injection > HEADER. 

<script src="//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

Add the following to Store Settings > Advanced > Page Header Code Injection.

<style>

  .hide-quantity {
  
    display: none;
    
    }
    
  </style>

<script>

  $( '.ProductItem .variant-option select' ).change ( function ( ) {
  
    let $quantity = $( '.product-quantity-input' );
    let $this =  $( this );
    
    let clss = 'hide-quantity';
    let s = $this.val ( );
    
    if ( s == 'Sample' ) {
    
      $quantity.addClass ( clss );
      
      $( 'input', $quantity ).val ( '1' );
      
      } else {
      
        $quantity.removeClass ( clss );
        
        }
        
    } );
    
  </script>

This is for a v7.1 site.

This code is general in that I built it based on the page presented. It does not take into account how other products may be configured. This code will not prevent someone from changing the quantity in the cart.

Let us know how it goes.

Hello I'm Thomas. I've been getting websites up and running for 26 years. I want to help you at whatever level meets your needs, from as little (if you're a DIYer) to as much as you need.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...