Biến giá sản phẩm từ 0 thành chữ Liên hệ hoặc vui lòng gọi

Flatsome

				
					/**
 * ------------------------------------------------------------------------------------------------
 * Chuyển giá 0 hoặc để trống thành Liên hệ
 * ------------------------------------------------------------------------------------------------
 */
add_filter( 'gutenberg_use_widgets_block_editor', '__return_false' );
add_filter( 'use_widgets_block_editor', '__return_false' );
function chowordpress_wc_custom_get_price_html( $price, $product ) {
    if ( $product->get_price() == 0 ) {
        if ( $product->is_on_sale() && $product->get_regular_price() ) {
            $regular_price = wc_get_price_to_display( $product, array( 'qty' => 1, 'price' => $product->get_regular_price() ) );
 
            $price = wc_format_price_range( $regular_price, __( 'Liên hệ', 'woocommerce' ) );
        } else {
            $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>';
        }
    }
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'chowordpress_wc_custom_get_price_html', 10, 2 );

/**
 * ------------------------------------------------------------------------------------------------
 * Chuyển giá thành Liên hệ khi hết hàng
 * ------------------------------------------------------------------------------------------------
 */
function chowordpress_oft_custom_get_price_html( $price, $product ) {
    if ( !is_admin() && !$product->is_in_stock()) {
       $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>';
    }
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'chowordpress_oft_custom_get_price_html', 99, 2 );
				
			

Woodmart

				
					/**
 * ------------------------------------------------------------------------------------------------
 * Chuyển giá 0 hoặc để trống thành Liên hệ
 * ------------------------------------------------------------------------------------------------
 */
add_filter( 'woocommerce_get_price_html', 'bbloomer_price_free_zero_empty', 9999, 2 );
   
function bbloomer_price_free_zero_empty( $price, $product ){
    if ( '' === $product->get_price() || 0 == $product->get_price() ) {
        $price = '<span class="woocommerce-Price-amount amount">FREE! OR TEXT YOU WANT</span>';
    }  
    return $price;
}