0

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.

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 ;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.