How to get current variation price in woocommerce single product page using ajax? - ajax

On Single product page of a variable product of woocommerce when user selects product options; woocommerce makes an ajax call and shows the variation price and inventory available. I just need to know how can I add my custom math to that ajax response? For example current variation price ajax response was 300 I want to add 30 more to that. Can anybody help plz?
I searched woocommerce files but no luck.

Related

Does Shopify Ajax API support Graphql?

I would like to manipulate the cart based on tags on products in the cart. I'm currently using the Shopify Ajax API to retrieve the cart contents and then the products in the cart. This leads to performance issues given the number of calls required. This is a classic issue addressed by GraphQL so I'm wondering if there is a solution available
How is making a call to the cart endpoint and getting back the contents a performance issue? Have you thought through what you are trying to do? If you do a single call to the cart, you get all the products in the cart. If you want to manipulate the products in the cart, what does that mean? If you are saying, geez, I need to see the tags of each product, and you then do an ajax call per product to get the tags, you are doing it wrong. Instead, when you place a product in the cart, add the special tag as a line item property. That way, when you want to play with the cart, you have all the data at your fingertips.
This is not a "classic GraphQL" kind of thing in my opinion, but instead, a question of perhaps not adopting the cleanest, fastest pattern of the many you could choose to use.

Shopify Script - Get a free X product when you spend Y amount

I'm searching all over the internet for a solution, and I hope you guys help me with that.
I want to do a shopify script that automatically add a specific free product if cart is over a specific amount (100$ for ex).
All i've find online is X% discount if cart is over $Y, but I want to add an existing product.
Is there a way to do it ?
Thanks in advance
You could do this with the shopify Ajax API (https://help.shopify.com/themes/development/getting-started/using-ajax-api).
With this API you can make a request to the cart GET /cart.js and get back the total_price. You can write some logic to say if that is > 100$ then post X product.
You can post a product to the cart with the Ajax API as well POST /cart/add.js
We wrote a little post on adding products to the cart with the Ajax API if you want to reference an example ajax request http://www.codeshopify.com/blog_posts/adding-to-cart-with-ajax

Hook in cart update on change

I have a Woocommerce One Page Checkout and I have the quantity input changed to a select box according this snippet.
Now I want that when I change my quantity with the select, the quantity in my shopping cart also updates with the selected quantity using AJAX. How can I achieve this in my functions.php?
The snippet later on that page does not what it should do. Can someone help me out?
Update:
Could this maybe part of my solution?

Adding a bespoke priced line item (handling cost) to shopify cart from external domain

Is it possible, using apps/api/ajax etc to have a shopify cart send off a request to an external site which calculates a price based on the carts contents and adds an item to the cart with said price?
At the moment what I think might be a way forward is:
Have a product "Handling" with a £0.01 price
Write an app that includes some scripttags that add options to cart items
When the options are changed the script contacts the external service with the cart contents and options
External service can then add a quantity of the "Handling" product to the cart based on the calculation, customer can remove this item if they wish, which will reset their options
Is this a remotely feasible plan? Have I listed anything that just isn't possible or would be more appropriately done in another way?
Many thanks for any guidance.

Apply Custom Option via Ajax to a product

Has anyone had any success in Applying a custom option to the product object via Ajax.
ie. A ajax request will get triggered when ever I select a custom option which changes the product price.
I have a ajax Block in the Product View page that depends on the Product Price. Since Magento Applies the Custom Options after the product is added to the cart , I am finding it difficult to render the ajax block with my updated product price.
Any idea's ?
Try this module, its good ajax cart and it has exactly what you need and you can customize it easily
https://github.com/hws47a/VF_AjaxCart

Resources