Woocommerce добавить определенные атрибуты на одной странице продукта - PullRequest
0 голосов
/ 03 октября 2019

У меня есть код с этого сайта .

   function isa_woo_get_one_pa(){
    $desired_att = 'weingut';   
    global $product;
    $attributes = $product->get_attributes();     
    if ( ! $attributes ) {
        return;
    }      
    $out = '';   
    foreach ( $attributes as $attribute ) {
        $name = $attribute->get_name();
        if ( $attribute->is_taxonomy() ) {
            $tax_slug = strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '_', $desired_att)));
            if ( $name == 'pa_' . $tax_slug ) {
                $terms = wp_get_post_terms( $product->get_id(), $name, 'all' );
                $tax = $terms[0]->taxonomy;
                $tax_object = get_taxonomy( $tax );
                if ( isset ( $tax_object->labels->singular_name ) ) {
                    $tax_label = $tax_object->labels->singular_name;
                } elseif ( isset( $tax_object->label ) ) {
                    $tax_label = $tax_object->label;
                    if ( 0 === strpos( $tax_label, 'Product ' ) ) {
                       $tax_label = substr( $tax_label, 8 );
                    }
                }
                  foreach ( $terms as $term ) {       
                    $out .= $tax_label . ': ';
                    $out .= $term->name . '<br />';                       
                }       
            }               
        } else {
            if ( $name == $desired_att ) {
                $out .= $name . ': ';
                $out .= esc_html( implode( ', ', $attribute->get_options() ) );
            }
        }       
    }

    echo $out;
}
add_action('woocommerce_before_single_product', 'isa_woo_get_one_pa');

Возможно ли добавить определенные атрибуты ('attribute1', attribut2 ', attribut3') и добавить класс css к метке и класс css к значению?

Iдействительно застрял ... THX

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...