How To Group Variations & Allow Only 1 Selection Per Product

The code in this download folder displays variations for each attribute in WooCommerce. Only 1 selection can be added to the cart. Example : In this case we use 2 attributes :

  1. Weight : 1 KG and 2 KG
  2. Frequency : 1 Time 2 Per Month 5 Per Month & 10 Per month

Variations display like this :

Group variations 1 selection

Every variation option for the weight attribute displays with every variation option for the frequency attribute.

Only 1 weight option can be selected with 1 corresponding frequency option. Users cannot select 2 KG frequency options when selecting 1 KG of weight or 1 KG frequency variations when selecting the 2 KG variation as seen in the following demo video.

Demo Video

Only 1 group selection per product is allowed to be added to the cart.

Works in any WordPress theme with or without usage of blocks.


There’s 3 simple steps :

  1. Upload the folder named woocommerce and file named attribute.js to your child theme folder.
  2. Copy and paste the PHP code to the end of your child themes functions file.
  3. Copy and paste the CSS to the end of your child themes style.css file.

Usage – Attributes & Variations

Swap out Weight and Frequency in the PHP and jQuery with the names of your attributes.

Setup your attributes and variations like normal with your own names and values.