Hi,
I have reduced all of my prices manually to the sale price (20% off the original price) but I would like to add the “compare at price” to be 20% more than my sale price.
I have over 5,000 products so bulk editing each compare at price is impossible.
How can I add a code so that it automatically creates my “compare at price” to be 20% more than my current “price”? I would essentially want to divide my current price by .80 to get my compare at price.
I found this code but not sure how to use it or if there is a better option?
/* Bulk update prices */
var prices = $('input[name^="product[variants_attributes]"][name$="[price]"]');
var compare_at = $('input[name^="product[variants_attributes]"][name$="[compare_at_price]"]');
var percentage = 0.2;
$.each(prices, function(key, price){
$(compare_at[key]).val($(price).val());
$(compare_at[key]).trigger("change");
$(price).val( ($(price).val() - ($(price).val() * percentage)).toFixed(2) );
$(price).trigger("change");
});
/* Revert price updates */
var prices = $('input[name^="product[variants_attributes]"][name$="[price]"]');
var compare_at = $('input[name^="product[variants_attributes]"][name$="[compare_at_price]"]');
$.each(compare_at, function(key, value){
$(prices[key]).val($(value).val()).trigger("change");
$(value).val('').trigger("change");
});