/* Get variation attribute based on product ID */
$product = new WC_Product_Variable( $product_id );
$variations = $product->get_available_variations();
$var_data = [];
foreach ($variations as $variation) {
if($variation[‘variation_id’] == $variation_id){
$var_data[] = $variation[‘attributes’];
}
}
/*Get attributes from loop*/
foreach($var_data[0] as $attrName => $var_name) {
echo $var_name;
}
Notice: Undefined variable: product_id in D:\xampp\htdocs\tracking_shipments\wp-content\themes\storefront\functions.php on line 160
Notice: Undefined offset: 0 in D:\xampp\htdocs\tracking_shipments\wp-content\themes\storefront\functions.php on line 170
Warning: Invalid argument supplied for foreach() in D:\xampp\htdocs\tracking_shipments\wp-content\themes\storefront\functions.php on line 170
LikeLike
Check $product_id, we need to send product ID using this variable.
LikeLiked by 1 person
Works fine on Woocommerce 3.2.5
Thanks for sharing!
LikeLiked by 1 person
Your welcome… 🙂
LikeLike