• Resolved nasirwp

    (@nasirwp)


    “Buy now or Add to cart” Redirect to contact page
    I want to redirect to the “Buy Now or Add to cart” Button to the Contact page, and after submitting the form its will auto redirect to the checkout page. (Contact form redirect to checkout work fine) Add to cart also redirect fine.

    My main issue, with the “Buy Now” Button how can redirect to the same place.

    <a key="31714" style=" margin-right: 2px;" class="button product_type_simple add_to_cart_button ajax_add_to_cart chk_out ">Buy Now</a>

    Add To cart :
    <a href="?add-to-cart=31714" data-quantity="1" class="button product_type_simple add_to_cart_button ajax_add_to_cart" data-product_id="31714" data-product_sku="" aria-label="Add “Online Listing” to your cart" rel="nofollow">Add to Cart</a>

    Please if you check this screenshot, you will better understand.
    https://prnt.sc/v5en5i

    Please, anyone, give me a solution? I want for Buy now or add to cart both are redirected to the specific page for specific products

      For redirect add to cart: I have used the below code.
    function my_custom_add_to_cart_redirect( $url ) {
    	
    	if ( ! isset( $_REQUEST['add-to-cart'] ) || ! is_numeric( $_REQUEST['add-to-cart'] ) ) {
    		return $url;
    	}
    	
    	$product_id = apply_filters( 'woocommerce_add_to_cart_product_id', absint( $_REQUEST['add-to-cart'] ) );
    	
    	// Only redirect the product IDs in the array to the checkout
    	if ( in_array( $product_id, array( 31714 ) ) ) {
    		//$url = WC()->cart->get_checkout_url();
    		$url = get_permalink( 533285 ); // URL to redirect to (1 is the page ID here)
    	}
    	
    	return $url;
    
    }
    add_filter( 'woocommerce_add_to_cart_redirect', 'my_custom_add_to_cart_redirect' );
    

    The page I need help with: https://burstbiz.com

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hi!

    I can’t advise on the custom code you’ve provided, but have you considered a plugin solution?

    You could use Product Add-Ons if you want the customer to send specific instructions or messages to you along with their order, or give custom personalisation information.

    Or you could look at Product Enquiry Form if you want customers to be able to correspond with you before they purchase.

    Thread Starter nasirwp

    (@nasirwp)

    Thanks for your reply.
    Yes, I have both plugin, Product Add Ons, and Product Enquiry Form.

    I think this is the best solution.

    My issue, Add to cart or buy now, it will go to custom from page. and the submit button will redirect to the checkout page.

    Certainly, I see what you’re asking.

    I’ll leave the issue open for a little while in case a developer from the community can chime in with a suggestion for you.

    You could also join the WooCommerce Slack Community where many developers do hang out: https://woocommerce.com/community-slack/

    If you’d like paid help from a developer, we’d also point you to our WooCommerce Customizations Page.

    Thread Starter nasirwp

    (@nasirwp)

    Thanks
    I will try

    Thread Starter nasirwp

    (@nasirwp)

    ” Product Enquiry Form”
    i did not got the solution in this plugin.
    i need to fix for redirect issue

    Since there haven’t been other replies yet, I’m going to close this for now. If you have any further questions, please feel free to start a new thread.

    Resolving.

    Thread Starter nasirwp

    (@nasirwp)

    Thanks

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘“Buy now or Add to cart” Redirect to contact page’ is closed to new replies.