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

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

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page