I am trying to link a product to a form so that after you purchase the product (nutrition Plan) you will be redirected to a questionnaire form page.

I would like to organise different forms for different products.

I am using woocommerce and paid membership pro for membership access.

Any help would be greatly appreciated.

Cheers Andrew

closed as off-topic by bueltge, cjbj, jgraup, Dave Romsey, Howdy_McGee Nov 29 '16 at 23:05

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

You've got a couple of options – you can use a plugin to achieve this, for instance this one: https://shopplugins.com/plugins/woocommerce-redirect-thank-you/

If you prefer to code this manually, this is how you'd generally redirect the user to a URL after they've made a purchase of a certain product (PS: this will also redirect the user if they buy the product as a part of a larger order).

You'll need the ID of the product, and the ID of the page you want to redirect to, where the questionnaire is. Alternatively, you can use any URL you want.

add_action('template_redirect', 'wc_redirect_after_purchase'); 
function wc_redirect_after_purchase() {
    global $wp;

    if (is_checkout() && !empty( $wp->query_vars['order-received'])){
        $order = new WC_Order($wp->query_vars['order-received']);
        $items = $order->get_items();

        foreach ($items as $item){
            $product_id = $item['product_id'];

            if ($product_id == 1234){
                $questionnaire_url = get_permalink(123); // ID of page with questionnaire
                wp_redirect($questionnaire_url);
                exit;
            }
        }
    }
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.