Hướng dẫn cách thay thế vị trí giá biến thể.

Hôm nay mình sẽ share cho các bạn 1 đoạn script nhỏ nhỏ để thay thế được giá biến thể vào vị trí giá tổng của sản phẩm nhé, có rất nhiều cách để thực hiện việc này, trước đây mình cũng có chia sẻ cách thay thế này bằng cách hook và di chuyển hook. Nhưng cách làm này là không tối ưu nên các bạn làm theo cách này sẽ tốt hơn rất nhiều.

Các bạn có thể tham khảo cách kia tại đây.

Các bạn thêm đoạn script vào đây giúp mình

Thêm script vào Flatsome
</div>
<div><script type="text/javascript">
jQuery(document).ready(function ($) {
jQuery(document).ready(function(event) {
var m = $('.price.product-page-price ').html();
jQuery('.single_variation_wrap').change(function(){
$('.woocommerce-variation-price').hide();
var p = $('.single_variation_wrap').find('.price').html();
$('.price.product-page-price').html(p);
});
jQuery('body').on('click','.reset_variations',function(event) {
$('.price.product-page-price').html(m);
});
});
});
</script></div>
<div class="syntaxhighlighter plain code-custom">

Đối với các theme khác thì các bạn có thể theme function này vào file functions.php nhé, cách nào cũng được.

Thêm function

function js_custom_price_pt(){;?>
<script type="text/javascript">
jQuery(document).ready(function ($) {
jQuery(document).ready(function(event) {
var m = $('.price.product-page-price ').html();
jQuery('.single_variation_wrap').change(function(){
$('.woocommerce-variation-price').hide();
var p = $('.single_variation_wrap').find('.price').html();
$('.price.product-page-price').html(p);
});
jQuery('body').on('click','.reset_variations',function(event) {
$('.price.product-page-price').html(m);
});
});
});
</script>
<?php }
add_action('wp_footer','js_custom_price_pt');

Chúc các bạn thành công

THIẾT KẾ WEB 68 – WEB68

EMAIL: info.thietkeweb68@gmail.com

SĐT: 0359373636 – 0902229139

WEBSITE: thietkeweb68.net

Trả lời

Email của bạn sẽ không được hiển thị công khai.