categories - How to call Primary Category for WordPress Woocommerce

admin2025-06-02  3

I have try for several hours to solve this but I am getting nowhere.

In the class-wc-structured-data I would like to add a Markup for "brand" as on my website the brand = the parent category

$markup['brand'] = $term = get_term_by('name', $name, 'product_cat');

I would like to call the wooocommerce parent category. With the above code I am getting the name as "False" instead of the parent category.

Can someone help me please ?

Thanks

FYI I know little coding.

I have try for several hours to solve this but I am getting nowhere.

In the class-wc-structured-data I would like to add a Markup for "brand" as on my website the brand = the parent category

$markup['brand'] = $term = get_term_by('name', $name, 'product_cat');

I would like to call the wooocommerce parent category. With the above code I am getting the name as "False" instead of the parent category.

Can someone help me please ?

Thanks

FYI I know little coding.

Share Improve this question edited Mar 16, 2019 at 17:25 Sicario asked Feb 25, 2019 at 13:01 SicarioSicario 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

As per WordPress Codex for the function

get_term_by( $field, $value, $taxonomy, $output, $filter );

If $value does not exist, the return value will be false. If $taxonomy exists and $field and $value combinations exist, the Term will be returned.

So, you need to check the value of $name in your code

$term = get_term_by('name', $name, 'product_cat');
$markup['brand']   = $term ;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748799919a313821.html

最新回复(0)