0

I am trying to wrap my result with <li>, but when I do so as in the code, I get funny results, as the result display way below.

do_action( 'woocommerce_after_shop_loop_item' );
$value = get_the_terms( $product->id, 'pa_package');

foreach ( $value as $values ) {
    echo "<li>";
    echo $values->name;
    echo "</li>";
}
3
  • 1
    Your code will echo you list items (without the required ol or ul wrapper) where ever the woocommerce hook runs. Can you clarify the question?
    – s_ha_dum
    Commented Nov 23, 2013 at 15:28
  • @s_ha_dum i have lots of modification that i want to do, but i think altering hooks for woocommerce will help me out? Where can i start?
    – localhost
    Commented Nov 24, 2013 at 12:57
  • Please follow up on the questions you asked, it's an important part of the process on WPSE - see What should I do when someone answers my question? and Why is voting important? for a deeper insight. Thank you! Commented Nov 27, 2013 at 22:07

1 Answer 1

1

You can hook into the action like this:

Code:

add_action( 'woocommerce_after_shop_loop_item', 'wpse124226_wc_product_attribute_list' );
function wpse124226_wc_product_attribute_list() {
    $value = get_the_terms( $product->id, 'pa_package');
    echo "<ul>";
    foreach ( $value as $values ) {
        echo "<li>";
        echo $values->name;
        echo "</li>";
    }
    echo "</ul>";
}

Take a look at the codex Plugin API to inform yourself about using hooks. BTW you can use woocommerce functions to get the attributes, especially get_attributes, take a look at the source at the woocommerce documentation. For an use-case take a look at the product-attributes.php file.

8
  • +1 to let you reach 2000 rep, you deserve it because you're (almost) the only user here who still answer WooCommerce questions :)
    – gmazzap
    Commented Nov 25, 2013 at 15:57
  • Haha, thanks, I'm trying to, because despite of the whole controversy I feel many woo question aren't worst then others I answer. And last but not least, the people behind just want a little bit of help, so why not giving it to them, if I can. @G.M. Commented Nov 25, 2013 at 16:19
  • For anyone wondering what controversy I'm talking about take a look at WordPress Development Meta. Commented Nov 25, 2013 at 16:42
  • @ialocin how do i know, what woocommerce calls its backend variables like u did pa_packages?
    – localhost
    Commented Nov 28, 2013 at 7:35
  • I have gotten pa_package from your code, generally woocommerce prefixes products attributes with pa_. @Nofel Commented Nov 28, 2013 at 10:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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