Woocommerce fetching category_ID from product page not working with variable products

This code is working fine with simple products, but it won’t work with variable products. I created a custom field percentage_markup in the product category page. I then use this field to add markup to the catalogue price.

Can anyone shed some light here please, I’m hopelessly stuck…

// identify category ID
global $post;
$terms = get_the_terms( $post->ID, ‘product_cat’ );
foreach ($terms as $term) {
$product_cat_id = $term->term_id;
break;
}
// fetch percentage_markup field from that category
$value = get_field(‘percentage_markup’, ‘category_’.$product_cat_id);

// return price
return roundnum(($price*$value), .10);
}

Read more here:: Woocommerce fetching category_ID from product page not working with variable products

Leave a Reply

Your email address will not be published. Required fields are marked *