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










1















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










share|improve this question






















  • 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















1















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










share|improve this question






















  • 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













1












1








1








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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

















  • 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












1 Answer
1






active

oldest

votes


















1














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.






share|improve this answer























  • 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










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
);



);













draft saved

draft discarded


















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









1














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.






share|improve this answer























  • 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















1














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.






share|improve this answer























  • 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













1












1








1







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










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 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

















  • 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
















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



















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite