[英]Check if product category page is not empty in Woocommerce
我收到此错误:
未捕获的错误:在 null 上调用成员 function get_price()
当类别/商店/存档页面为空或没有产品时:
function display_loop_item_stock_notice() {
global $product;
// For active product price: Free shipping || NO Free shipping
$text = $product->get_price() >= 500 ? '<span>Free shipping</span>' : '<span>Free shipping from 500 €</span>';
// In stock
if ( $product->is_in_stock() ) {
$text = '<span>In stock</span>' . ' <span class="free-shipping">' . $text . '</span>';
}
// Out of stock
else {
$text = '<span><strong>' . get_field( 'date_of_availability' ) . '</strong></span>' . '<span class="free-shipping">' . $text . '</span>';
echo '<div class="remaining text-center">' . $text . '</div>';
}
}
add_action( 'woocommerce_after_shop_loop_item', 'display_loop_item_stock_notice', 90 );
您可以检查 $product 是否为 null。
...
global $product;
if (is_null($product)) {
return;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.