May 29, 2014

How to manage bundles in default Woocommerce?

How to manage bundles in default Woocommerce?

  1. Create a Variable product
  2. Add Only one attribute e.g. Packages
  3. Enter attribute values with pipe signs
  4. Go to variations tab and pre select attributes values for each value
  5. Put different prices for each variation

Ready!
Now use the following code to get an array or packages and variations:

$packages = array();
if($variable){
$product_details = new WC_Product_Variable(get_the_ID());
$variations = $product_details->get_available_variations();
if(!empty($variations)){
foreach($variations as $data){
$attr = $data['attributes'];
$package_key = array_keys($attr);
$attr = array_filter($attr, 'strlen');
$attr = current($attr);
$packages[$attr] = $data['variation_id'];
}
$package_key = current($package_key);
}
}

Last updated: May 29, 2014