Occasional error
-
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!
- The topic ‘Occasional error’ is closed to new replies.