Поддержка WooCommerce Коллапс для шорткода атрибутов в вукомерс

  • Здравствуйте, появился вопрос в плане отображения атрибутов товара на базе вукомерс. В php не силен, потому прощу помощи.
    Нашел код который отображает атрибуты товара в виде списка. Сайт стоит на бутстрапе. Нужно этот список сделать ввиде коллапса
    Прилагаю код который нашел и картинку того как нужно отобразить.
    Пробовал самостоятельно сделать, но к сожалению не хватает знаний в пышке.
    Огромное спасибо за помощь

    http://joxi.ru/KAxWM1VtMO9By2

    /**
     * Attributes shortcode callback.
     */
    function so_39394127_attributes_shortcode( $atts ) {
    
        global $product;
    
        if( ! is_object( $product ) || ! $product->has_attributes() ){
            return;
        }
    
        // parse the shortcode attributes
        $args = shortcode_atts( array(
            'attributes' => array_keys( $product->get_attributes() ), // by default show all attributes
        ), $atts );
    
        // is pass an attributes param, turn into array
        if( is_string( $args['attributes'] ) ){
            $args['attributes'] = array_map( 'trim', explode( '|' , $args['attributes'] ) );
        }
    
        // start with a null string because shortcodes need to return not echo a value
        $html = '';
    
        if( ! empty( $args['attributes'] ) ){
    
            foreach ( $args['attributes'] as $attribute ) {
    
                // get the WC-standard attribute taxonomy name
                $taxonomy = strpos( $attribute, 'pa_' ) === false ? wc_attribute_taxonomy_name( $attribute ) : $attribute;
    
                if( taxonomy_is_product_attribute( $taxonomy ) ){
    
                    // Get the attribute label.
                    $attribute_label = wc_attribute_label( $taxonomy );
    
                    // Build the html string with the label followed by a clickable list of terms.
                    // heads up that in WC2.7 $product->id needs to be $product->get_id()
                    $html .= get_the_term_list( $product->id, $taxonomy, '<li class="bullet-arrow">' . $attribute_label . ': ' , ', ', '</li>' );   
                }
    
            }
    
            // if we have anything to display, wrap it in a <ul> for proper markup
            // OR: delete these lines if you only wish to return the <li> elements
            if( $html ){
                $html = '<ul class="product-attributes">' . $html . '</ul>';
            }
    
        }
    
        return $html;
    }
    add_shortcode( 'display_attributes', 'so_39394127_attributes_shortcode' );
    • Тема изменена 5 лет, 4 месяца назад пользователем SeVlad. Причина: Оформляйте, пож, код как следует

    Страница, с которой нужна помощь: [войдите, чтобы увидеть ссылку]

  • Тема «Коллапс для шорткода атрибутов в вукомерс» закрыта для новых ответов.