• Resolved yonsky

    (@yonsky)


    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)
  • Plugin Author Maarten

    (@maartenbelmans)

    Hi @yonsky

    The problem is that your “buy now” button simply redirects to an “add to cart” url without passing any of the field data. As such, the system can not add the product to cart because it expects fields.

    Custom coding this is not so easy. You would have to pass along the fields too.

    Thread Starter yonsky

    (@yonsky)

    Thank you for the quick reply.

    Can you share a way to add a “Buy Now” that will work with the plugin?

    Plugin Author Maarten

    (@maartenbelmans)

    We do not have that code at the moment, unfortunately

    Thread Starter yonsky

    (@yonsky)

    Ok.

    I think that adding a buy now button alongside the add to cart button is a basic feature that most ecommerce shops would like to use. Please consider adding that option to your plugin.

    Thank you.

    Plugin Author Maarten

    (@maartenbelmans)

    I added it to our to-do list.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding a Buy Button on single product page’ is closed to new replies.