Generating an Add to Cart Link Dynamically
-
Hello,
I have a custom template that is pulling in product information. Depending on a few fields that a user selects (the product itself and whether or not it’s a variation), I want to create an add to cart button that is customized depending on the choices.
I’ve used the foxy cart docs to create a link like:
<a href="https://YOURSTORE.foxycart.com/cart?price=998.00&name=Safe+Heat+Kit+with+Stove+Plug&code=319">Add To Cart</a>
However, FoxyShop adds a hash to all of the field values so the above does not correctly add the items to the cart. When you output a basic add to cart link with the foxyshop_product_link() function you can see the hashed values in the link it generates:
<a href="https://YOURSTORE.foxycart.com/cart?price||16cfe69c0f454432676b1b9bcacb5dca2d9a69329166838594c8b8067686b5b0=998.00&name||a458787648af974d86a68afda7ed1e180fef7d1b41a5b0311866a1ae3af50d83=Safe+Heat+Kit+with+Stove+Plug&code||2c226fcf865000059fbf09fecea44c6915ec050ab48a65b1246d743f6773dba1=319" class="foxyshop_button">Add To Cart</a>
I’ve tried adding a link with the shortcode;
<?php echo do_shortcode('[product name="extherminate-safe-heat-kit" variations="Extra=Cord"]Add To Cart[/product]'); ?>
However, the variation is created and added on the spot rather than accessing the pre-existing variation (with the same name and value) I made with the FoxyShop backend. Meaning that the price difference (p+50.00) doesn’t factor in.
Could someone please help me by letting my know either:
a) How to generate an add to cart button dynamically (including pulling in the proper hash values)
or
b) use the shortcode with a variation that I have previously created with the backend
Thanks,
V
- The topic ‘Generating an Add to Cart Link Dynamically’ is closed to new replies.