我在wordpress/woocommerce上有商店。当我在列表末尾添加已售罄产品的功能时,我得到警告:
Warning: Attempt to read property "ID" on null in .../ftp/wp/wp-includes/class-wp-query.php on line 4044
Warning: Attempt to read property "post_title" on null in .../ftp/wp/wp-includes/class-wp-query.php on line 4046
Warning: Attempt to read property "post_name" on null in .../ftp/wp/wp-includes/class-wp-query.php on line 4048
Warning: Attempt to read property "post_type" on null in .../ftp/wp/wp-includes/class-wp-query.php on line 4196
Warning: Undefined array key 0 in .../ftp/wp/wp-includes/capabilities.php on line 76
第4031至4064行:
public function is_page( $page = '' ) {
if ( ! $this->is_page ) {
return false;
}
if ( empty( $page ) ) {
return true;
}
$page_obj = $this->get_queried_object();
$page = array_map( 'strval', (array) $page );
if ( in_array( (string) $page_obj->ID, $page, true ) ) {
return true;
} elseif ( in_array( $page_obj->post_title, $page, true ) ) {
return true;
} elseif ( in_array( $page_obj->post_name, $page, true ) ) {
return true;
} else {
foreach ( $page as $pagepath ) {
if ( ! strpos( $pagepath, '/' ) ) {
continue;
}
$pagepath_obj = get_page_by_path( $pagepath );
if ( $pagepath_obj && ( $pagepath_obj->ID == $page_obj->ID ) ) {
return true;
}
}
}
return false;
}
产品排序代码:
/**
* Sorting out of stock WooCommerce products - Order product collections by stock status, in-stock products first.
*/
class iWC_Orderby_Stock_Status
{
public function __construct()
{
// Check if WooCommerce is active
if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) {
add_filter('posts_clauses', array($this, 'order_by_stock_status'), 2000);
}
}
public function order_by_stock_status($posts_clauses)
{
global $wpdb;
// only change query on WooCommerce loops
if (is_woocommerce() && (is_shop() || is_product_category() || is_product_tag())) {
$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
$posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
$posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
}
return $posts_clauses;
}
}
new iWC_Orderby_Stock_Status;
/**
* END - Order product collections by stock status, instock products first.
*/
当我删除这些代码时,我没有得到警告。
有什么办法可以删除这些警告吗?
my shop: customoweplugin .pl
如果您不知道您所做的更改可能会对代码产生什么影响,并且您至少没有了解到您确信这些更改不会破坏任何东西,那么首先不要进行这些更改!
我不推荐这样做,但如果你只是不想看到这个警告,那么你可以使用"错误控制操作符">. 只需添加"@">在像
这样的表达式之前@$page_obj->ID
它不会解决错误,但只会阻止他们显示!
在这里阅读更多关于错误控制操作符的信息:https://www.php.net/manual/en/language.operators.errorcontrol.php