Hey there mra13,
Here’s what I figured out that the issue is.
Embedding the shortcode normally in a page or post, normally, works:
[wp_cart_button name="Test Product" price="19.95"]
But I don’t use the shortcode in the post. Because I’ve been using the plugin more programmatically, I’ve been using it to generate product listings and so on. So I have the site owner enter a price in a field, and I reproduce the form that the shortcode creates on the page in a loop to show products.
So the products are entered as a custom post type and a custom field holds the price – that gets stored in the variable $the_price and rendered.
That lets me create pages like this:
https://woodsbodygoods.com/thegoods/
https://woodsbodygoods.com/products/lip-shimmer/
(Note: Right now because the store is closed, I made the “Add to Cart” buttons that my code generated go away)
When the plugin didn’t check for price validation, that used to work great.
So I’ve run some tests.
Just reproducing the form still works no problem, if I do this:
<p><strong>A great product</strong> ($29.95)</p>
<div class="wp_cart_button_wrapper">
<form method="post" class="wp-cart-button-form" action="" style="display:inline" onsubmit="return ReadForm(this, true);" >
<input type="submit" value="Add to Cart" /><input type="hidden" name="wspsc_product" value="Test Product" />
<input type="hidden" name="price" value="29.95" /><input type="hidden" name="shipping" value="0" />
<input type="hidden" name="addcart" value="1" />
<input type="hidden" name="cartLink" value="https://woodsbodygoods.com/test-page/" />
<input type="hidden" name="product_tmp" value="Test Product" />
<input type="hidden" name="item_number" value="" />
<input type="hidden" name="hash_one" value="a0709891fbffed660233b1bcf7f7a66f" />
</form>
</div><!-- ends button-wrapper -->
But because I need to move the price in there programmatically, I’ve added the first line and changed the second line in the form:
$the_price = 29.95;
<input type="hidden" name="price" value="<?php echo $the_price; ?>" />
As soon as I do this, the form renders okay, but I get the price validation failure when I click the add to cart button. Basically, replacing the hard coded value with a variable throws it.
As a different approach to this whole problem could work, I’ve also tried rendering the form using PHP’s do_shortcode command with [wp_cart_button name=”Test Product” price=”19.95″] in it, but it does not seem to work for me – nothing renders.
Any thoughts?
Thanks!