wordpress/woocommerce: Remove price if zero

前端 未结 5 1617
庸人自扰
庸人自扰 2021-02-04 22:38

I\'m busy with a wordpress/woocommerce site and I\'d like to hide the price of an item when it\'s zero on the product category/archive page.

I\'ve tried looking on the

5条回答
  •  死守一世寂寞
    2021-02-04 23:01

    This one finally did it for me (using woocommerce 3.0.8):

    function cw_change_product_price_display( $price ) {
        $clear = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($price))))));
        if($clear == "0 00"){
          return '';
        }
        return $price;
      }
      add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
      add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
    

提交回复
热议问题