0
votes

I'm in the process of moving a site over from Infusionsoft's singular order form pages (no cart, you buy one product at a time) to a WooCommerce powered site with a shopping cart. That part is going well.

However, there's certain circumstances where my client wants the site to behave like the Infusionsoft checkout. Basically... user goes to a URL that is nothing but a checkout page with a specified product, the only thing you can purchase. This would be for if they were doing a class and offering a special offer to attendees only (via a custom URL).

I've tried WooCommerce Single Product Checkout, and while it gets close it doesn't do exactly what I'd want. The two big issues are 1) It still requires the user to add the item to the cart and 2) The cart is still site wide, meaning if the user had previously added another product to the cart now the checkout on the single product page wants to check both products out.

Any suggestions? Thanks

1

1 Answers

0
votes

Ended up writing my own plugin. Here's the code

function add_and_forward($atts, $content=null) {
    global $woocommerce;
    $ids =  explode(",", $atts['product_ids']);
    $empty_cart = $atts['empty_cart'];
    $checkout_url = $woocommerce->cart->get_checkout_url();
    //if empty cart
    if($empty_cart === "1")
        $woocommerce->cart->empty_cart(); 
    foreach($ids as $id)
        $woocommerce->cart->add_to_cart($id);
    wp_redirect( $checkout_url );
} add_shortcode('add_and_forward', 'add_and_forward');

Only downside is that it still is a site wide cart, but the client said it was ok, at least this gives them the option to empty the users cart or not.

Run it with the following shortcode

[add_and_forward product_ids="1748" empty_cart="1"]