而不是消除循环/添加到购物车。php模板全部放在一起,为什么不把价格挂钩成html Woocommerce挂钩呢?
/*
* Remove price HTML if stock is null
*
* Sources:
* http://woocommerce.wp-a2z.org/oik_api/wc_productget_stock_quantity/
*/
add_filter( "woocommerce_get_price_html", "wphelpsanjay_remove_price_if_no_stock", 10, 2 );
add_filter( "woocommerce_variable_price_html", "wphelpsanjay_remove_price_if_no_stock", 10, 2 );
function wphelpsanjay_remove_price_if_no_stock( $price, $product ) {
if ( null === $product->get_stock_quantity()) {
return "";
}
return $price;
}