Chuyển giá tiền thành chữ “Liên hệ” trong woocommerce

Đoạn code dưới đây sẽ giúp các bạn chuyển  thành chữ “Liên hệ”. Bạn chỉ cần chèn đoạn code sau vào file functions.php của theme bạn đang sử dụng là được

Code chuyển 0đ thành chữ “Liên hệ”

Dán code dưới vào file functions.php của theme

1
2
3
4
5
6
7
8
9
10
11
12
13
function devvn_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, __( 'Free!', 'woocommerce' ) );
        } else {
            $price = '<span class="amount">' . __( 'Liên hệ', 'woocommerce' ) . '</span>';
        }
    }
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'devvn_wc_custom_get_price_html', 10, 2 );

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

Đoạn code này sẽ giúp bạn hiển thị giá thành chữ “Liên hệ” khi set sản phẩm đó là hết hàng. Chỉ cần thêm đoạn code sau vào functions.php của theme đang active là được

1
2
3
4
5
6
7
function devvn_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', 'devvn_oft_custom_get_price_html', 99, 2 );

 

DỊCH VỤ SEO TẠI ĐỒNG THÁP – HINATECH

Địa chỉ: Số 11, Đường Nguyễn Thị Lựu, Phường 4, Thành phố Cao Lãnh, tỉnh Đồng Tháp

Điện thoại: 0357.592.458 – 0945.996.684 – Mail: info@thietkewebstiedongthap.com

Website: www.thietkewebsitedongthap.com – Fanepage: https://www.facebook.com/thietkewebsitedongthap

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *