Anonymous
Отображение атрибутов продукта в подробном описании WooCommerce
Сообщение
Anonymous » 04 ноя 2024, 12:37
Я пытаюсь автоматически отображать атрибуты продукта в конце подробного описания, но мой код отображает их в кратком описании. Как мне настроить это так, чтобы оно отображалось либо в виде вкладки, либо в подробном описании?
Код работает отлично с точки зрения отображения атрибутов продукта, но размещение неправильное.
Код: Выделить всё
/* 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) . '
';
} else {
$display_result .= $name . ': ';
$display_result .= esc_html( implode( ', ', $attribute->get_options() ) ) . '
';
}
}
echo $display_result;
}
add_action('woocommerce_single_product_summary', 'njengah_woo_attribute', 25);
Подробнее здесь:
https://stackoverflow.com/questions/791 ... escription
1730713078
Anonymous
Я пытаюсь автоматически отображать атрибуты продукта в конце подробного описания, но мой код отображает их в кратком описании. Как мне настроить это так, чтобы оно отображалось либо в виде вкладки, либо в подробном описании? Код работает отлично с точки зрения отображения атрибутов продукта, но размещение неправильное. [code]/* 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) . ' '; } else { $display_result .= $name . ': '; $display_result .= esc_html( implode( ', ', $attribute->get_options() ) ) . ' '; } } echo $display_result; } add_action('woocommerce_single_product_summary', 'njengah_woo_attribute', 25);[/code] Подробнее здесь: [url]https://stackoverflow.com/questions/79154898/display-product-attributes-in-woocommerce-long-description[/url]