如何在 Woocommerce 中的价格前添加自定义文本

如何在类别视图和产品页面中使用片段向我的 Woocoomerce 价格添加自定义文本?


function sv_change_product_html( $price_html, $product ) {

    $unit_price = get_post_meta( $product->id, 'unit_price', true );

    if ( ! empty( $unit_price ) ) {

        $price_html = '<span class="amount">' . wc_price( $unit_price ) . ' / Stück</span>';    

    }


    return $price_html;

}

add_filter( 'woocommerce_get_price_html', 'sv_change_product_html', 10, 2 );


饮歌长啸
浏览 208回答 2
2回答

动漫人物

这工作正常。但我只想将这个剪断用于某些产品。是否有用于某些产品 ID 的代码?谢谢

隔江千里

add_filter("wc_price","addtext",10,4);function addtext($return, $price, $args, $unformatted_price){&nbsp; &nbsp; if(is_product_category() || is_shop() || is_product()){&nbsp; &nbsp; &nbsp; &nbsp; $return =&nbsp; 'like Preis:'.$return;&nbsp; &nbsp; }&nbsp; &nbsp; return $return;}
打开App,查看更多内容
随时随地看视频慕课网APP