Home>Support>Deprecated function related to number of products per page

Deprecated function related to number of products per page

I’m using Vantage with WooCommerce 4.3 and have a few modifications to my functions.php file using a Child Theme. After updating to WooCommerce 4.3 I’m getting a message on my WordPress Dashboard saying “…ate_function() is deprecated in /home/georgegl/public_html/wpmain/wp-content/themes/vantage-child/functions.php on line 16” Unfortunately, the message overlaps the black sidebar of the Dashboard so I can’t see the first part of the message!

However this is what is on line 16 — code to display 40 products per page on my Shop Category pages:
add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 40;’ ), 20 );

For now, the code does still seem to be working so 40 products per page are displaying, but obviously if it’s not quite right I want to change it. What should I change it to?

Thanks,
Helen

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 4 years, 1 month ago Andrew Misplon
    Hi, I Work Here

    Hi Helen

    If you set WP_DEBUG to false in your WordPress wp-config.php file the warning won’t print.

    https://wordpress.org/support/article/debugging-in-wordpress/

    The filter loop_shop_per_page doesn’t appear to be deprecated.

    https://github.com/woocommerce/woocommerce/blob/dbf3e99292eb07569295dddda8154db75d805d69/includes/class-wc-query.php#L412

    https://docs.woocommerce.com/document/change-number-of-products-displayed-per-page/

  2. 4 years, 1 month ago George Glazer

    Hi Andrew,

    Thanks for that link to https://docs.woocommerce.com/document/change-number-of-products-displayed-per-page/ ! When I compared the code there with the code I had, I realized the code for changing the number of products per page from the default had been changed.

    This is what I had:

    // Display 40 products per page
    //add_filter( ‘loop_shop_per_page’, create_function( ‘$cols’, ‘return 40;’ ), 20 ); //

    This is the format they showed at the link you provided:

    /** Display 40 products per page.
    * Change number of products that are displayed per page (shop page) */
    add_filter( ‘loop_shop_per_page’, ‘new_loop_shop_per_page’, 20 );

    function new_loop_shop_per_page( $cols ) {
    // $cols contains the current number of products per page based on the value stored on Options -> Reading
    // Return the number of products you wanna show per page.
    $cols = 40;
    return $cols;
    }
    I put the new code in, and the error message disappeared!

    Many thanks,
    Helen

  3. 4 years, 1 month ago Andrew Misplon
    Hi, I Work Here

    Hi Helen

    Super, I’m really glad to hear you’re making progress and that the link inadvertently helped.

    Cheers for now :)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More