Php 如果产品价格为';这比商业中的特定金额要高
在Woocommerce中,如果价格高于59欧元,我试图在价格之前添加文本 我尝试了以下代码(和其他代码),但都不起作用:Php 如果产品价格为';这比商业中的特定金额要高,php,wordpress,woocommerce,hook-woocommerce,price,Php,Wordpress,Woocommerce,Hook Woocommerce,Price,在Woocommerce中,如果价格高于59欧元,我试图在价格之前添加文本 我尝试了以下代码(和其他代码),但都不起作用: add_filter( 'woocommerce_get_price_html', 'custom_price_message' ); function custom_price_message( $price ) { if ($price>='59'){ $new_price = $price .__('(GRATIS!)'); } return $new_
add_filter( 'woocommerce_get_price_html', 'custom_price_message' );
function custom_price_message( $price ) {
if ($price>='59'){
$new_price = $price .__('(GRATIS!)');
}
return $new_price;
}
如果高于59,如何在产品价格前添加
(免费!)
文本?更新:您应该尝试以下重新访问的功能代码:
add_filter( 'woocommerce_get_price_html', 'prepend_text_to_product_price', 20, 2 );
function prepend_text_to_product_price( $price_html, $product ) {
// Only on frontend and excluding min/max prices on variable products
if( is_admin() || $product->is_type('variable') )
return $price_html;
// Get product price
$price = (float) $product->get_price(); // Regular price
if( $price > 15 )
$price_html = '<span>'.__('(GRATIS)', 'woocommerce' ).'</span> '.$price_html;
return $price_html;
}
据此:
if( $price > 15 && is_product() ){
if( $price > 15 && ( is_product() || is_shop() || is_product_category() || is_product_tag() ){
对于单一产品页面和归档页面您将替换此行:
if( $price > 15 ){
if( $price > 15 ){
据此:
if( $price > 15 && is_product() ){
if( $price > 15 && ( is_product() || is_shop() || is_product_category() || is_product_tag() ){
谢谢!可能只有一页吗?Thanks@delfinoweb接受答案并不意味着放弃它。您应该需要单击答案旁边的灰色复选标记图标(而不是箭头图标),将其从灰色切换为绿色。因此,在问题的原始作者已经接受的答案旁边,有一个彩色的复选标记表示接受。