WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
Calling certain product_cat (3 posts)

  1. damian.smith
    Member
    Posted 1 year 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 :(

    http://wordpress.org/extend/plugins/woocommerce/

  2. damian.smith
    Member
    Posted 1 year 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
    Member
    Posted 1 year ago #

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

    <?php
    $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

About this Topic