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’);
​
Is this website live/publicly available? It’ll be easier to debug if it is.