Mã dán thay đổi giá tiền, thay đổi giá tiền thuộc tính, giá tiền biến thể woo wordpress
Trong woocommerce cho phép ta chọn loại sản phẩm (Sản phẩm 1 giá, sản phẩm nhiều giá theo nhiều kiểu hình …) Khi chọn sản phẩm có giá tùy vào từng loại của sản phẩm thì giá khi hiển thị ra sẽ có dạng giá min – giá max (VD: 20.000 VNĐ – 90.000 VNĐ)



Mã số 1 dán ở flatsome / advanted : ô thẻ body :
<script type="text/javascript">
(function ($) {
'use strict';
jQuery(document).ready(function ($) {
$(document).on('change',function(){
var price_html = $('.product .woocommerce-variation-price').html();
console.log(price_html+"Price");
if ( price_html == '') {
return;
}
else{
$('p.price' ).html($('.product .woocommerce-variation-price').html());
$('.product .woocommerce-variation-price').hide();
}
});
});
})(jQuery);
</script>
Mã số 2 dán ở funtions.php trong mục edit themes :
Thêm đoạn code sau vào file functions.php mà theme bạn đang sử dụng
function wc_wc20_variation_price_format( $price, $product ) {
//Main Price
$prices = array( $product->get_variation_price( 'min', true ), $product->get_variation_price( 'max', true ) );
$price = $prices[0] !== $prices[1] ? sprintf( __( 'Giá từ: %1$s', 'woocommerce' ), wc_price( $prices[0] ) ) : wc_price( $prices[0] );
// Sale Price
$prices = array( $product->get_variation_regular_price( 'min', true ), $product->get_variation_regular_price( 'max', true ) );
sort( $prices );
$saleprice = $prices[0] !== $prices[1] ? wc_price( $prices[0] ) : wc_price( $prices[0] );
if ( $price !== $saleprice ) {
$price = '<del>' . $saleprice . '</del> <ins>' . $price . '</ins>';
}
return $price;
}
add_filter( 'woocommerce_variable_sale_price_html', 'wc_wc20_variation_price_format', 10, 2 );
add_filter( 'woocommerce_variable_price_html', 'wc_wc20_variation_price_format', 10, 2 );
Bài viết liên quan :
Share 248GB siêu khóa học Udemy chọn lọc bởi Khắn Muối
Chia sẻ link tải Divi Builder kèm API Key Bản Quyền Update Lifetime
Năm 2018 nên kinh doanh gì đây độc đáo, 9 cách kinh doanh mới nhỏ
Viết bài Seo - Tối ưu Seo web giúp thu hút lượng lớn khách hàng mục tiêu
Bạn cần tìm một đơn vị thiết kế website giá rẻ, uy tín tại Thái Bình
CrazyBlog v1.9 – Theme WordPress miễn phí dùng cho blogs kiếm tiền Adsense hay Affiliate Business
