How to link a form to a product [closed]

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;
            }
        }
    }
}

tech