rAthus

[WP][WooCommerce] get prices & weights of variable products

Mar 23rd, 2020
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.46 KB | None | 0 0
  1. // anywhere in the theme's content-single-product.php
  2. $poids_prix = array();
  3. if ($product->is_type('variable'))
  4.     foreach($product->get_available_variations() as $key=>$variation)
  5.         if ($variation['attributes'] and $variation['attributes']['attribute_poids'] and $variation['weight'])
  6.             $poids_prix[$variation['attributes']['attribute_poids']] = array('poids_kg'=>$variation['weight']*1,'prix_eur'=>$variation['display_price']*1);
  7. echo json_encode($poids_prix);
Add Comment
Please, Sign In to add comment