Kalden
Kalden

Reputation: 222

Shopify Jquery change the price of product

Hey Im new to shopify and am trying to figure out their API Im trying to add a bunch of checkboxes that will alter the total amount of the product. I have a code that is changing the json class json_product.price to be 20.00 dollars. Im doing this in the product_variants.liquid file. This is the code so far

{{ 'option_selection.js' | shopify_asset_url | script_tag }}
<script>
var json_product = {{ product | json }};
console.log(json_product);
$('.colorBlue').click(function(){
  calDollars = 30;
  $(".price").text('$'+calDollars+'.00 USD'),
  json_product.price_max = 2000,
  json_product.price = 2000;
  console.log(json_product);
});
</script>

It seems to be changing the price on the json file, and I made it alter the shown price on the product page, but when I click add to cart it stays at the original $0.00 price. Any clues on how I can get this to work?

Upvotes: 1

Views: 2449

Answers (1)

David Lazar
David Lazar

Reputation: 11425

You cannot alter pricing using client-side code. If you want to present different prices for a product, let the customer pick different variants.

You could create a callback to an App of your own creation, and using that App, you could alter the price of a product. Note that if you do that, all your customers would see the altered price.

Upvotes: 1

Related Questions