Echo category name in woocommerce2019 Community Moderator Electionproduct category image in custom woocommerce themewoocommerce product categories shortcode pagination not workingRestrict Related Products by Product Categories Woocommercewoocommerce: join post and product categoryGet the id of a WooCommerce category, by nameWoocommerce product-category-description on productpageWordpress/Woocommerce - Editing word before product price only in certain categoriesSort Woocommerce Products from a product category and custom meta_keyExclude Woocommerce categoryAppend current category name to product title on woocommerce category archives
Replacing Windows 7 security updates with anti-virus?
Silly Sally's Movie
Can infringement of a trademark be pursued for using a company's name in a sentence?
Does the Bracer of Flying Daggers benefit from the Dueling Fighting style?
What is the dot in “1.2.4."
Why must traveling waves have the same amplitude to form a standing wave?
Touchscreen-controlled dentist office snowman collector game
What to do when during a meeting client people start to fight (even physically) with each others?
What is the likely impact on flights of grounding an entire aircraft series?
Potentiometer like component
Word for a person who has no opinion about whether god exists
Does Linux have system calls to access all the features of the file systems it supports?
Time dilation for a moving electronic clock
Am I not good enough for you?
Want to switch to tankless, but can I use my existing wiring?
Do f-stop and exposure time perfectly cancel?
Is going from continuous data to categorical always wrong?
Decoding assembly instructions in a Game Boy disassembler
What has been your most complicated TikZ drawing?
When is a batch class instantiated when you schedule it?
What exactly is the purpose of connection links straped between the rocket and the launch pad
Is a lawful good "antagonist" effective?
Running a subshell from the middle of the current command
How does Dispel Magic work against Stoneskin?
Echo category name in woocommerce
2019 Community Moderator Electionproduct category image in custom woocommerce themewoocommerce product categories shortcode pagination not workingRestrict Related Products by Product Categories Woocommercewoocommerce: join post and product categoryGet the id of a WooCommerce category, by nameWoocommerce product-category-description on productpageWordpress/Woocommerce - Editing word before product price only in certain categoriesSort Woocommerce Products from a product category and custom meta_keyExclude Woocommerce categoryAppend current category name to product title on woocommerce category archives
I would like to change the Text of the related products, wich is at the end of the product detail page. At the moment i'm displaying This could be interesting by using this code
<h2><?php esc_html_e( 'This could be interesting', 'woocommerce' ); ?></h2>
What i would like to display is Our favorite category name
I tried to expand the code with this snippet, without any success
<?php echo wc_get_product_category_list($product->get_id()) ?>
How is it possible to get this function done?
Thx
php wordpress woocommerce
add a comment |
I would like to change the Text of the related products, wich is at the end of the product detail page. At the moment i'm displaying This could be interesting by using this code
<h2><?php esc_html_e( 'This could be interesting', 'woocommerce' ); ?></h2>
What i would like to display is Our favorite category name
I tried to expand the code with this snippet, without any success
<?php echo wc_get_product_category_list($product->get_id()) ?>
How is it possible to get this function done?
Thx
php wordpress woocommerce
get_the_term_list( $product_id, 'product_cat' ); - Returns the product categories in a list. - comma separated
– mujuonly
Mar 7 at 9:57
Like this ?<h2><?php esc_html_e( '( $product_id, 'product_cat' );', 'woocommerce' ); ?></h2>
– p_e_88
Mar 7 at 10:02
<?php echo get_the_term_list( $product_id, 'product_cat' ); ?>
– mujuonly
Mar 7 at 10:04
Thx Mujuonly, but that's display the subcategory and the parent category. I'm looking for the active category. So for example product has parent category A and subcategory B. On the product details page should be displayed the Subcategory B.
– p_e_88
Mar 7 at 10:10
add a comment |
I would like to change the Text of the related products, wich is at the end of the product detail page. At the moment i'm displaying This could be interesting by using this code
<h2><?php esc_html_e( 'This could be interesting', 'woocommerce' ); ?></h2>
What i would like to display is Our favorite category name
I tried to expand the code with this snippet, without any success
<?php echo wc_get_product_category_list($product->get_id()) ?>
How is it possible to get this function done?
Thx
php wordpress woocommerce
I would like to change the Text of the related products, wich is at the end of the product detail page. At the moment i'm displaying This could be interesting by using this code
<h2><?php esc_html_e( 'This could be interesting', 'woocommerce' ); ?></h2>
What i would like to display is Our favorite category name
I tried to expand the code with this snippet, without any success
<?php echo wc_get_product_category_list($product->get_id()) ?>
How is it possible to get this function done?
Thx
php wordpress woocommerce
php wordpress woocommerce
asked Mar 7 at 9:54
p_e_88p_e_88
561213
561213
get_the_term_list( $product_id, 'product_cat' ); - Returns the product categories in a list. - comma separated
– mujuonly
Mar 7 at 9:57
Like this ?<h2><?php esc_html_e( '( $product_id, 'product_cat' );', 'woocommerce' ); ?></h2>
– p_e_88
Mar 7 at 10:02
<?php echo get_the_term_list( $product_id, 'product_cat' ); ?>
– mujuonly
Mar 7 at 10:04
Thx Mujuonly, but that's display the subcategory and the parent category. I'm looking for the active category. So for example product has parent category A and subcategory B. On the product details page should be displayed the Subcategory B.
– p_e_88
Mar 7 at 10:10
add a comment |
get_the_term_list( $product_id, 'product_cat' ); - Returns the product categories in a list. - comma separated
– mujuonly
Mar 7 at 9:57
Like this ?<h2><?php esc_html_e( '( $product_id, 'product_cat' );', 'woocommerce' ); ?></h2>
– p_e_88
Mar 7 at 10:02
<?php echo get_the_term_list( $product_id, 'product_cat' ); ?>
– mujuonly
Mar 7 at 10:04
Thx Mujuonly, but that's display the subcategory and the parent category. I'm looking for the active category. So for example product has parent category A and subcategory B. On the product details page should be displayed the Subcategory B.
– p_e_88
Mar 7 at 10:10
get_the_term_list( $product_id, 'product_cat' ); - Returns the product categories in a list. - comma separated
– mujuonly
Mar 7 at 9:57
get_the_term_list( $product_id, 'product_cat' ); - Returns the product categories in a list. - comma separated
– mujuonly
Mar 7 at 9:57
Like this ?
<h2><?php esc_html_e( '( $product_id, 'product_cat' );', 'woocommerce' ); ?></h2>– p_e_88
Mar 7 at 10:02
Like this ?
<h2><?php esc_html_e( '( $product_id, 'product_cat' );', 'woocommerce' ); ?></h2>– p_e_88
Mar 7 at 10:02
<?php echo get_the_term_list( $product_id, 'product_cat' ); ?>
– mujuonly
Mar 7 at 10:04
<?php echo get_the_term_list( $product_id, 'product_cat' ); ?>
– mujuonly
Mar 7 at 10:04
Thx Mujuonly, but that's display the subcategory and the parent category. I'm looking for the active category. So for example product has parent category A and subcategory B. On the product details page should be displayed the Subcategory B.
– p_e_88
Mar 7 at 10:10
Thx Mujuonly, but that's display the subcategory and the parent category. I'm looking for the active category. So for example product has parent category A and subcategory B. On the product details page should be displayed the Subcategory B.
– p_e_88
Mar 7 at 10:10
add a comment |
1 Answer
1
active
oldest
votes
Here is a little helper function that you could put in your functions.php
function get_favorite_category_title_for( $product_id )
$title = __('This could be interesting', 'woocommerce');
$cats = wp_get_post_terms( $product_id, 'product_cat' );
if( count($cats) > 0 )
$title = __( 'Our favorite ', 'woocommerce' ) . $cats[0]->name;
return $title;
and then replace the h2 tag with:
<h2><?php echo get_favorite_category_title_for( get_queried_object_id() ); ?></h2>
you can change get_queried_object_id with the $product->get_id() if you have access to $product object.
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
To get the deepest category replace thewp_get_post_termsline with$cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') );it should work.
– Saqib Amin
Mar 7 at 10:22
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040799%2fecho-category-name-in-woocommerce%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here is a little helper function that you could put in your functions.php
function get_favorite_category_title_for( $product_id )
$title = __('This could be interesting', 'woocommerce');
$cats = wp_get_post_terms( $product_id, 'product_cat' );
if( count($cats) > 0 )
$title = __( 'Our favorite ', 'woocommerce' ) . $cats[0]->name;
return $title;
and then replace the h2 tag with:
<h2><?php echo get_favorite_category_title_for( get_queried_object_id() ); ?></h2>
you can change get_queried_object_id with the $product->get_id() if you have access to $product object.
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
To get the deepest category replace thewp_get_post_termsline with$cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') );it should work.
– Saqib Amin
Mar 7 at 10:22
add a comment |
Here is a little helper function that you could put in your functions.php
function get_favorite_category_title_for( $product_id )
$title = __('This could be interesting', 'woocommerce');
$cats = wp_get_post_terms( $product_id, 'product_cat' );
if( count($cats) > 0 )
$title = __( 'Our favorite ', 'woocommerce' ) . $cats[0]->name;
return $title;
and then replace the h2 tag with:
<h2><?php echo get_favorite_category_title_for( get_queried_object_id() ); ?></h2>
you can change get_queried_object_id with the $product->get_id() if you have access to $product object.
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
To get the deepest category replace thewp_get_post_termsline with$cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') );it should work.
– Saqib Amin
Mar 7 at 10:22
add a comment |
Here is a little helper function that you could put in your functions.php
function get_favorite_category_title_for( $product_id )
$title = __('This could be interesting', 'woocommerce');
$cats = wp_get_post_terms( $product_id, 'product_cat' );
if( count($cats) > 0 )
$title = __( 'Our favorite ', 'woocommerce' ) . $cats[0]->name;
return $title;
and then replace the h2 tag with:
<h2><?php echo get_favorite_category_title_for( get_queried_object_id() ); ?></h2>
you can change get_queried_object_id with the $product->get_id() if you have access to $product object.
Here is a little helper function that you could put in your functions.php
function get_favorite_category_title_for( $product_id )
$title = __('This could be interesting', 'woocommerce');
$cats = wp_get_post_terms( $product_id, 'product_cat' );
if( count($cats) > 0 )
$title = __( 'Our favorite ', 'woocommerce' ) . $cats[0]->name;
return $title;
and then replace the h2 tag with:
<h2><?php echo get_favorite_category_title_for( get_queried_object_id() ); ?></h2>
you can change get_queried_object_id with the $product->get_id() if you have access to $product object.
answered Mar 7 at 10:10
Saqib AminSaqib Amin
1,017715
1,017715
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
To get the deepest category replace thewp_get_post_termsline with$cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') );it should work.
– Saqib Amin
Mar 7 at 10:22
add a comment |
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
To get the deepest category replace thewp_get_post_termsline with$cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') );it should work.
– Saqib Amin
Mar 7 at 10:22
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
Perfect Saqib, but how can i just display the current active category name?Example. Product has the parent category A and the subcategory B. It just should display the current active category. Another example - my breadcrumbs looks like this Home > A > B > Product. So in this case it should display B. Home > A > Product. In this case A
– p_e_88
Mar 7 at 10:14
To get the deepest category replace the
wp_get_post_terms line with $cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') ); it should work.– Saqib Amin
Mar 7 at 10:22
To get the deepest category replace the
wp_get_post_terms line with $cats = wp_get_post_terms( $product_id, 'product_cat', array('orderby'=> 'id', 'order'=>'DESC') ); it should work.– Saqib Amin
Mar 7 at 10:22
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55040799%2fecho-category-name-in-woocommerce%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
get_the_term_list( $product_id, 'product_cat' ); - Returns the product categories in a list. - comma separated
– mujuonly
Mar 7 at 9:57
Like this ?
<h2><?php esc_html_e( '( $product_id, 'product_cat' );', 'woocommerce' ); ?></h2>– p_e_88
Mar 7 at 10:02
<?php echo get_the_term_list( $product_id, 'product_cat' ); ?>
– mujuonly
Mar 7 at 10:04
Thx Mujuonly, but that's display the subcategory and the parent category. I'm looking for the active category. So for example product has parent category A and subcategory B. On the product details page should be displayed the Subcategory B.
– p_e_88
Mar 7 at 10:10