Adding a Buy Button on single product page
-
Hi,
I’m using advanced product fields plugin to add extra product fields to my woocommerce products.
I’ve added a “Buy Now” button alongside the “Add to Cart” button at the single product page by using the following code:
add_action ('woocommerce_after_add_to_cart_button', 'ecommercehints_buy_now', 10, 0); function ecommercehints_buy_now() { global $product; if ( ! $product->is_type( 'simple' ) ) return; echo '<a href="/cart/?add-to-cart='.$product->get_ID().'" class="button">Buy Now</a>'; };
The problem is, when a user clicks on the “Buy Now” button without filling in the required product fields it redirects to the cart page without adding the product to cart because its required fields weren’t filled.
How can I add a “Buy Now” button alongside the “Add to Cart” button when there are required fields?
The button needs to validate the required fields before redirection to cart.
Thank you.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Adding a Buy Button on single product page’ is closed to new replies.