• Hello,
    I want to show attribute “color” in a template (content-product.php).
    I need a way to write the comma as separator between values except for last item

    Here’s the function I use:

    function echo_colors(){
    $colors = get_the_terms( $product->id, 'pa_color');
    	if(is_array($colors)) {
    		$out = "<p class='colors'>";
    		foreach ( $colors as $color ) {
    $out .= implode( ', ', (array)$color->name );
    }
    $out .= "</p>";
    echo $out;
    }
    }
    
    add_action('woocommerce_echo_color','echo_color'); // content-product

    Then I call back the action in the content-product.php where I want the list of colors appear:

    <?php do_action( 'woocommerce_echo_color' ); ?>

    Here’s what I get : GREENBLUERED.
    The comas don’t appear.

    Please anybody could help me?
    Regards;

    https://wordpress.org/plugins/woocommerce/

  • The topic ‘Show attributes in a template (with implode function)’ is closed to new replies.