Price issue with single product with variations and related products

When i’m selecting and option for a variable product, the price apply to the single product AND the related products at the bottom of the page. Anyone have an idea ?

​

function prevent_related_product_price_change() {
global $product;

// Check if we are on a single product page and the product has variations
if (is_product() && $product->is_type(‘variable’)) {
?>
<script>
jQuery(document).ready(function($) {
// Store the initial price of the related products
var originalRelatedProductPrices = [];

// Loop through each related product
$(‘.et-db #et-boc .et-l .et_pb_wc_related_products_0_tb_body ul.products li.product .price, .et-db #et-boc .et-l .et_pb_wc_related_products_0_tb_body ul.products li.product .price .amount’).each(function() {
originalRelatedProductPrices.push($(this).find(‘.price’).html());
});

// Listen for changes in the variation select
$(‘select[name=”attribute_pa_achetez-en-lot”]’).change(function() {
// Check if a variation is selected
if ($(this).val() != ”) {
// Restore the original prices of the related products
$(‘.et-db #et-boc .et-l .et_pb_wc_related_products_0_tb_body ul.products li.product .price, .et-db #et-boc .et-l .et_pb_wc_related_products_0_tb_body ul.products li.product .price .amount’).each(function(index) {
$(this).find(‘.price’).html(originalRelatedProductPrices[index]);
});
}
});
});
</script>
<?php
}
}

add_action(‘wp_footer’, ‘prevent_related_product_price_change’);

&#x200B;

1 Comment

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer