cart->add_to_cart()",Check this out: What I've built is a calculator plugin for a client that makes suggestions on the amount of product a customer should buy. Pretty simp"/>cart->add_to_cart()"">cart->add_to_cart()",Check this out: What I've built is a calculator plugin for a client that makes suggestions on the amount of product a customer should buy. Pretty simp"/>cart->add_to_cart()""/>cart->add_to_cart()",Check this out: What I've built is a calculator plugin for a client that makes suggestions on the amount of product a customer should buy. Pretty simp "/>

Tony D. on "[Plugin: WooCommerce] WooComm: Issue adding products to cart via: WC()->cart->add_to_cart()"

ساخت وبلاگ

Check this out:

What I've built is a calculator plugin for a client that makes suggestions on the amount of product a customer should buy. Pretty simple. Calculator displays on the home page and is a basic form that posts entries upon submit.

On submit it redirects to my calculator.php where it displays the results of the home page calculation. There are 4 different forms on this page and each displays different products that the user can select from. The form that the user selects from this page will determine what product gets placed in the cart.

Here's some code from the calculator.php (display page mentioned above):

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <div class="quantity_display"> <h1>Product Group 1</h1><br /> <span>Quantity: <?php echo $adults ?> - ProductNameHere</span> <?php if ($kids > 0){ ?> <br /><span>Quantity: <?php echo $kids?> - OtherProductNameHere(added per kid)</span> <?php } ?> </div> <br /><input type="submit" name="submit-form-1" value="Buy Now" />
</form>

On submit, the form submits to PHP_SELF so I can catch the actual submit. And since I'm working with multiple forms this page, I created the below conditional statement:

if (isset($_POST['submit-form-1'])){ echo '<script>alert("submit button hit. woot!"); </script>'; // Hardcoded product IDs $adultsProductID = 96; $kidsProductID = 90; // Populate shopping cart - NOT WORKING - HALP WC()->cart->add_to_cart($adultsProductID,$adults); WC()->cart->add_to_cart($kidsProductID,$kids);
}

Here's what's boggling my mind with this issue.. If I pull the WC() calls out of this condition and allow the page to intercept them on load, literally Idea out the condition and placing the calls outside of the brackets, it adds these two products to the cart. But when I place the WC() calls in the condition and try to pick them up on form submit, I'm dead in the water.

Thoughts?

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 112 تاريخ : يکشنبه 29 فروردين 1395 ساعت: 5:47