I am trying to list out product categories as a list

  • Farm Cycle: 6 Months

    The code below output as
    Farm Cycle: 6 Months, KADUNA

    add_action( 'wpo_wcpdf_after_item_meta', 'wpo_wcpdf_show_product_categories', 10, 3 );
    function wpo_wcpdf_show_product_categories ( $template_type, $item, $order ) {
        // get a comma separated list of categories (category links stripped)
        if (isset($item['product'])) {
            echo '<div class="product-categories">DETAILS:<br/> '.strip_tags( wc_get_product_category_list( $item['product']->get_id() ) ).'</div>';

    Please try this code this will give you categories in list format: echo '<ul>' . wc_get_product_category_list( $item['product']->get_id(), '</li><li>', '<li>', '</li>' ) . '</ul>';

    • It works fine but how can I strip the tags, I tried <code> echo '<ul>' .strip_tags(wc_get_product_category_list( $item['product']->get_id(), '</li><li>', '<li>', '</li>' )) . '</ul>'; </code> – Odutola Abisoye Jun 12 '19 at 13:03
    • If you will strip the tags then it will not display as a list. – Bhupen Jun 12 '19 at 13:08
    • Thank you so much, I appreciate your help, how can I exclude a particular category – Odutola Abisoye Jun 12 '19 at 13:19
    • I was able to replace the URL using preg_replace('/\b((https?|ftp|file):\/\/|www\.)[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i' – Odutola Abisoye Jun 12 '19 at 13:29

    Your Answer

    By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

    Not the answer you're looking for? Browse other questions tagged or ask your own question.