I am trying to automatically display product attributes at the end of the long description but my code makes it appear in the short description. How would I adjust this to come either as a tab by itself or in the long description?
The code is working perfectly in terms of showing the attributes on the product but the placement is wrong.
/* Vis alle produkt attributter på vareside */
function njengah_woo_attribute(){
global $product;
$attributes = $product->get_attributes();
if ( ! $attributes ) {
return;
}
$display_result = '';
foreach ( $attributes as $attribute ) {
if ( $attribute->get_variation() ) {
continue;
}
$name = $attribute->get_name();
if ( $attribute->is_taxonomy() ) {
$terms = wp_get_post_terms( $product->get_id(), $name, 'all' );
$njengahtax = $terms[0]->taxonomy;
$njengah_object_taxonomy = get_taxonomy($njengahtax);
if ( isset ($njengah_object_taxonomy->labels->singular_name) ) {
$tax_label = $njengah_object_taxonomy->labels->singular_name;
} elseif ( isset( $njengah_object_taxonomy->label ) ) {
$tax_label = $njengah_object_taxonomy->label;
if ( 0 === strpos( $tax_label, 'Product ' ) ) {
$tax_label = substr( $tax_label, 8 );
}
}
$display_result .= $tax_label . ': ';
$tax_terms = array();
foreach ( $terms as $term ) {
$single_term = esc_html( $term->name );
array_push( $tax_terms, $single_term );
}
$display_result .= implode(', ', $tax_terms) . '<br />';
} else {
$display_result .= $name . ': ';
$display_result .= esc_html( implode( ', ', $attribute->get_options() ) ) . '<br />';
}
}
echo $display_result;
}
add_action('woocommerce_single_product_summary', 'njengah_woo_attribute', 25);