Calling certain product_cat (3 posts)

  1. damian.smith
    Posted 3 years ago #

    I have been trying to write some PHP script for some time now and have finally given in!

    Basically I need to write a bit of script that will call in different product_cat depending on the current product_cat.

    So if I am viewing a product that is under the category "spades" I need to display a list of related categories such as "spade handles, spade cleaning products"

    (spades is just an example!)

    I am guessing it will require an if, else kind of setup but cant get it working :(


  2. damian.smith
    Posted 3 years ago #

    sorry need to clarify that better after reading! Setup would need to be:

    if product_cat = "spades"
    echo "spade handles, spade cleaning"

    if product_cat = "plants"
    echo "pots, compost, food"

    etc etc etc

  3. damian.smith
    Posted 3 years ago #

    I have this so far, but simply doesn't work, any ideas on what needs modifying would be great.

    $terms = get_the_terms( $post->ID, 'product_cat' );
    $term = current($terms);
    if ($term == "safety-range") {
    echo "<h1>hello</h1>";

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic