[Share Code] Chuyển 0đ thành chữ “Liên hệ” trong Woocommerce WordPress

woocomerce plugin - ThemeVareno.com

Chuyển 0đ thành chữ “Liên hệ” trong Woocommerce WordPress

Chỉ cần coppy đoạn code dưới đây chèn vào file functions.php của theme active hoặc child theme, sẽ chuyển 0đ thành chữ “Liên hệ” trong Woocommerce WordPress

function vareno_wc_custom_get_price_html( $price, $product ) {
    if ( ! $product->get_price() ) {
        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, __( 'Free!', 'woocommerce' ) );
        } else {
            $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>';
        }
    }
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'vareno_wc_custom_get_price_html', 10, 2 );

Code Chuyển giá thành “Liên hệ” khi hết hàng trong Woocommerce

Chỉ cần coppy đoạn code dưới đây chèn vào file functions.php của theme active hoặc child theme, sẽ giúp chuyển giá thành “Liên hệ” khi hết hàng trong Woocommerce

function vareno_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', 'vareno_oft_custom_get_price_html', 99, 2 );