skip to Main Content

For fast loading in mobile view i want to remove woocommerce related products, what is the code to be added in function.php?
and I do not want to use CSS, thankyou.

2

Answers


  1. You can use wordpress inbuilt function – wp_is_mobile()
    https://developer.wordpress.org/reference/functions/wp_is_mobile/

    your complete code will be-

    if (wp_is_mobile()) {
         remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20 );
    }
    
    Login or Signup to reply.
  2. The function woocommerce_output_related_products is pluggable. So you can just re-write it.

    See: WooCommerce Code Reference

    Include this in your functions.php

    
    function woocommerce_output_related_products() {
        // Check if mobile and bail if so.
        if (wp_is_mobile()) return;
        $args = array(
            'posts_per_page' => 4,
            'columns'        => 4,
            'orderby'        => 'rand', // @codingStandardsIgnoreLine.
        );
    
        woocommerce_related_products( apply_filters( 'woocommerce_output_related_products_args', $args ) );
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search