Woocommerce (wordpress.org)
isabelcastillo.com/woocommerce-product-attributes-functions
- Feltételes űrlapmezők logikai összekapcsolással
This is just like Example 2, but with added CSS selectors for easy styling. Another difference is that this is output in an HTML unordered list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
function isa_woocommerce_all_pa(){ global $product; $attributes = $product->get_attributes(); if ( ! $attributes ) { return; } $out = '<ul class="custom-attributes">'; foreach ( $attributes as $attribute ) { // skip variations if ( $attribute['is_variation'] ) { continue; } if ( $attribute['is_taxonomy'] ) { $terms = wp_get_post_terms( $product->id, $attribute['name'], 'all' ); // get the taxonomy $tax = $terms[0]->taxonomy; // get the tax object $tax_object = get_taxonomy($tax); // get tax label if ( isset ($tax_object->labels->name) ) { $tax_label = $tax_object->labels->name; } elseif ( isset( $tax_object->label ) ) { $tax_label = $tax_object->label; } foreach ( $terms as $term ) { $out .= '<li class="' . esc_attr( $attribute['name'] ) . ' ' . esc_attr( $term->slug ) . '">'; $out .= '<span class="attribute-label">' . $tax_label . ': </span> '; $out .= '<span class="attribute-value">' . $term->name . '</span></li>'; } } else { $out .= '<li class="' . sanitize_title($attribute['name']) . ' ' . sanitize_title($attribute['value']) . '">'; $out .= '<span class="attribute-label">' . $attribute['name'] . ': </span> '; $out .= '<span class="attribute-value">' . $attribute['value'] . '</span></li>'; } } $out .= '</ul>'; echo $out; } add_action('woocommerce_single_product_summary', 'isa_woocommerce_all_pa', 25); |