Can't set the correct separator for array conversion to string. I am using
echo .implode( ",", $terms_array ).;
The output is: array1array2array3 instead of array1,array2,array3
In sandbox it works fine, but when I put code to WordPress, it's not working.
What can be a reason?
function wc_show_attribute_links_prodcart() {
global $post;
$attribute_names = array( 'pa_attr1', 'pa_attr2','pa_attr3' );
foreach ( $attribute_names as $attribute_name ) {
$taxonomy = get_taxonomy( $attribute_name );
if ( $taxonomy && ! is_wp_error( $taxonomy ) ) {
$terms = wp_get_post_terms( $post->ID, $attribute_name );
$terms_array = array();
if ( ! empty( $terms ) ) {
foreach ( $terms as $term ) {
$archive_link = get_term_link( $term->slug, $attribute_name );
$full_line = '<a href="' . $archive_link . '">'. $term->name . '</a>';
array_push( $terms_array, $full_line );
}
//echo .implode( ",", $terms_array );
echo implode( ',', $terms_array );
}
}
}
}