wordpress - Using checkboxes for variations in WooCommerce to allow multiple choice -


i've been using woocommerce while 1 issue causing me problem. client i'm making site provides training courses , presentations, , partiular product (or presentation) allows several different options added cart, each own price.

so, base price zero. there 8 different presentations user can select via checkbox on existing website - somehow need replicate using woocommerce on new site can use drop downs variations, , far can see allows 1 option chosen. feasible way can see working if add 8 different dropdowns each 8 presentations within them , customer selects many different ones want. bit cumbersome though , potentially can cause user error (selecting same presentation twice example).

i have attached screenshot of i'd ideally within woocommerce, there way achievable? don't mind using plugins if it's way.

enter image description here

you can way:

1) edit content-single-product.php:

2) product $product = wc_get_product( $productid )

3) check if $product->product_type == "variable"

4) variants of current product , list checkboxes:

$variations = $product->get_available_variations();  foreach ( $variations $variation ) {  $variationid = $variation['variation_id'];  echo '<input type="checkbox" name="variations[]" value="' . $variationid . '" />  }  echo '<input type="checkbox" name="product_id" value="' . $product->id . '" /> 

5) after can process $_post , add variations cart programatically:

if ( !empty( $_post['variations'] ) ) {  $productid = $_post['product_id']; $qty = 1; $buyvariations = $_post['variations'];  foreach ( $buyvariations $variationid ) {  wc()->cart->add_to_cart( $productid, $qty, $variationid );  }  } 

6) sanitization, validation , status messaging on you, process should works.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -