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 badges1 Answer
Reset to default 0As per WordPress Codex for the function
get_term_by( $field, $value, $taxonomy, $output, $filter );
If
$value
does not exist, the return value will befalse
. 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 ;