WooCommerce Blocks - Добавить краткое описание товара в сетку товаров - PullRequest
0 голосов
/ 24 февраля 2020

Итак, я впервые использую новые блоки WooCommerce. На главной странице моего сайта я включил блок «ProductBestSellers» и блок «ProductOnSale». Оба эти блока показывают макет в стиле сетки для самых продаваемых продуктов или продуктов в продаже.

Для нужного мне дизайна мне пришлось добавить несколько оберток в html, и поэтому я клонировал хранилище отсюда; WooCommerce Gutenberg Blocks

Добавленный html работает, но теперь мне нужно включить краткое описание продукта в эти блоки. Я редактировал AbstractProductGrid. php следующим образом;

AbstractProductGrid. php

/**
 * Render a single products.
 * Edited: 24/02/2020 
 *
 * Added wrappers to display content with padding borders and other styling
 *
 * @param int $id Product ID.
 * @return string Rendered product output.
 */
public function render_product( $id ) {
    $product = wc_get_product( $id );

    if ( ! $product ) {
        return '';
    }

    $data = (object) array(
        'permalink'     => esc_url( $product->get_permalink() ),
        'description'   => $this->get_description_html( $product ), <--- Add product short description
        'image'         => $this->get_image_html( $product ),
        'title'         => $this->get_title_html( $product ),
        'rating'        => $this->get_rating_html( $product ),
        'price'         => $this->get_price_html( $product ),
        'badge'         => $this->get_sale_badge_html( $product ),
        'button'        => $this->get_button_html( $product ),
    );

    return apply_filters(
        'woocommerce_blocks_product_grid_item_html',
        "<li class=\"wc-block-grid__product\">
            <div class=\"wc-block-grid__product__wrapper\">
                <div class=\"wc-block-grid__product__items\">
                    <a href=\"{$data->permalink}\" class=\"wc-block-grid__product-link\">
                        {$data->image}
                        {$data->title}
                    </a>
                    {$data->badge}
                    {$data->rating}
                    {$data->description}
                    <div class=\"wc-block-grid__product__price-wrapper\">
                        {$data->price}
                        {$data->button}
                    </div>
                </div>
            </div>
        </li>",
        $data,
        $product
    );
}

/**
 * Get the product short description.
 *
 * @param \WC_Product $product Product.
 * @return string
 */
protected function get_description_html( $product ) {
    if ( empty( $this->attributes['contentVisibility']['description'] ) ) {
        return '<p class="purple">The short description is empty</p>';
    }
    return '<div class="wc-block-grid__description">' . $product->get_short_description() ? $product->get_short_description() : wc_trim_string( $product->get_description(), 400 ) . '</div>';
}

Приведенный выше код возвращает пустой атрибут, как я могу включить краткое описание для новые блоки WooCommerce?

...