0

The shop page of WooCommerce is based on the archive-product.php file. In this file, a loop is called:

    <?php woocommerce_product_loop_start(); ?>

            <?php woocommerce_product_subcategories(); ?>

            <?php while ( have_posts() ) : the_post(); ?>

                <?php
                    /**
                     * woocommerce_shop_loop hook.
                     *
                     * @hooked WC_Structured_Data::generate_product_data() - 10
                     */
                    do_action( 'woocommerce_shop_loop' );
                ?>

                <?php wc_get_template_part( 'content', 'product' ); ?>

            <?php endwhile; // end of the loop. ?>

In this loop, product data is generated:

public function generate_product_data( $product = null ) {
        if ( ! is_object( $product ) ) {
            global $product;
        }

        if ( ! is_a( $product, 'WC_Product' ) ) {
            return;
        }

        $shop_name       = get_bloginfo( 'name' );
        $shop_url        = home_url();
        $currency        = get_woocommerce_currency();
        $markup          = array();
        $markup['@type'] = 'Product';
        $markup['@id']   = get_permalink( $product->get_id() );
        $markup['url']   = $markup['@id'];
        $markup['name']  = $product->get_name();

        if ( apply_filters( 'woocommerce_structured_data_product_limit', is_product_taxonomy() || is_shop() ) ) {
            $this->set_data( apply_filters( 'woocommerce_structured_data_product_limited', $markup, $product ) );
            return;
        }

        if ( '' !== $product->get_price() ) {
            $markup_offer = array(
                '@type'         => 'Offer',
                'priceCurrency' => $currency,
                'availability'  => 'https://schema.org/' . $stock = ( $product->is_in_stock() ? 'InStock' : 'OutOfStock' ),
                'sku'           => $product->get_sku(),
                'image'         => wp_get_attachment_url( $product->get_image_id() ),
                'description'   => $product->get_description(),
                'seller'        => array(
                    '@type' => 'Organization',
                    'name'  => $shop_name,
                    'url'   => $shop_url,
                ),
            );
...

There is a line in the generate_product_data function calling for the product description.

I'd like to adapt my template or add a function in my functions.php file so the description is no longer added to my product archive page. However, it should be added to my single product page. Product archive page & single product page use the same woocommerce_shop_loop however.

How should I adapt the template or add code to my functions file to remove this product description? I have long descriptions for my products & don't want these to be added to the product archive pages.

0

The solution was for the following for the7 template: Solution

If anybody knows how to implement this in the functions.php file so I don't have to update this when my theme updates, shoot!

0

For this specific theme you can add

remove_action('woocommerce_shop_loop_item_desc','dt_woocommerce_template_loop_product_short_desc', 15);

in functions.php of the child theme to remove the action, dt_woocommerce_template_loop_product_short_desc this function is added to woocommerce_shop_loop_item_desc, by using remove_action it'll be removed.

Update: It seems like you are removing action before init, child theme's function is executed before parent theme, kindly try

function remove_parent_action() {                                            
    remove_action('woocommerce_shop_loop_item_desc','dt_woocommerce_template_loop_product_short_desc', 15);
}
add_filter('init', 'remove_parent_action');
  • Hi Akshat, I tried to add this function to my functions.php file but it did not work unfortunately. In the meantime, I have gained some more insight about the hooks, which I have posted here: wordpress.stackexchange.com/questions/333556/… – BarrieO Apr 5 at 9:36
  • Ideally this should have worked, you'll have to debug if there's anything missed, or you can try adding higher priority to remove action. – Akshat Apr 6 at 14:11
  • OK Akshat, I'll give it another try later on. Shouldn't my priority be exactly the same as the which was used when adding the action? – BarrieO Apr 6 at 18:40
  • no, the priority should be either equal or greater than the add_action priority. – Akshat Apr 11 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.