最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

categories - How to call Primary Category for WordPress Woocommerce

matteradmin10PV0评论

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 ;
Post a comment

comment list (0)

  1. No comments so far