• Resolved ron441241

    (@ron441241)


    I added this code to my theme functions to enable random products on home page:

    // Set default orderby query to “rand” option for shop archive pages
    add_filter(‘woocommerce_get_catalog_ordering_args’, ‘shop_default_orderby_rand’);
    function shop_default_orderby_rand($args) { if( is_shop() && ( ! isset($_GET[‘orderby’]) || ‘menu_order’ === $_GET[‘orderby’] ) ) { $args[‘orderby’] = ‘rand’; return ($args); }
    }

    Code works well however I am seeing an error occasionally but not all the time. Currently using PHP 7.4

    Notice: Trying to access array offset on value of type null in?/home2/abc/public_html/xyz/wp-content/plugins/woocommerce/includes/class-wc-query.php?on line?521

    Notice: Trying to access array offset on value of type null in?/home2/abc/public_html/xyz/wp-content/plugins/woocommerce/includes/class-wc-query.php?on line?522

    This is the code found in wp-content/plugins/woocommerce/includes/class-wc-query.php

    public function product_query( $q ) {
    if ( ! is_feed() ) {
    $ordering = $this->get_catalog_ordering_args();
    $q->set( ‘orderby’, $ordering[‘orderby’] );
    $q->set( ‘order’, $ordering[‘order’] );

            if ( isset( $ordering['meta_key'] ) ) {
                $q->set( 'meta_key', $ordering['meta_key'] );
            }
        }

    Any help to fix this would be appreciated. I did contact theme developer however didn’t receive much help. Thanks!

Viewing 1 replies (of 1 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @ron441241

    For reference, these particular forums are meant for general support with the core functionality of WooCommerce itself. For development and custom coding questions, it’s best to ask for insight related to those on either the WooCommerce Advanced Facebook group or the WooCommerce Community Slack. Many of our developers hang out there and will be able to offer insights into your question. You can also seek help from the following:

    I wish I could help more, but hopefully, this gets you going in the right direction to get some further insight/information.

Viewing 1 replies (of 1 total)
  • The topic ‘Occasional error’ is closed to new replies.