Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果产品价格为';这比商业中的特定金额要高_Php_Wordpress_Woocommerce_Hook Woocommerce_Price - Fatal编程技术网

Php 如果产品价格为';这比商业中的特定金额要高

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_

在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_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接受答案并不意味着放弃它。您应该需要单击答案旁边的灰色复选标记图标(而不是箭头图标),将其从灰色切换为绿色。因此,在问题的原始作者已经接受的答案旁边,有一个彩色的复选标记表示接受。