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

banner home FINAL 1050x121 1
huong dan su dung wordpress 2

Đ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ệ”

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

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

function devvn_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 = '' . __( 'Liên hệ', 'woocommerce' ) . '';
        }
    }
    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

function devvn_oft_custom_get_price_html( $price, $product ) {
    if ( !is_admin() && !$product->is_in_stock()) {
       $price = '' . __( 'Liên hệ', 'woocommerce' ) . '';
    }
    return $price;
}
add_filter( 'woocommerce_get_price_html', 'devvn_oft_custom_get_price_html', 99, 2 );
Chúc các bạn thành công!
Nguồn: Lê Văn Toản
0/5 (0 Reviews)

# KHÁM PHÁ CÁC HASHTAG HÀNG ĐẦU

Theo dõi và cập nhật tin tức AZ9s thông qua các kênh truyền thông:

- Zalo Channel

- Facebook Channel

- Youtube Channel

banner home FINAL 1050x121 1
0 0 votes
Article Rating
Nhận thông báo qua Email
Nhận thông báo cho
guest

0 Comments
Inline Feedbacks
View all comments
0
Hãy để lại bình luận của bạn!x
()
x