0

An unregistered user buys a product from a certain category (take into account the ID), adds it to the cart and goes to the order processing. If it is registered, it makes out an order. If not, redirecting it for registration and back for ordering.

After making an order, if user bought a product of a certain category, redirecting it to the custom page "Thank You", or immediately to the edit page of the account "edit-account" in the personal account.

Illustration of the desired actions of the user.

In principle, for an unregistered user, it is possible to enable the automatic creation of an account when buying products. It is necessary to add the condition of buying products from a certain category. And need to make a redirect after placing an order.

I shall be very glad to your help!

0
add_action('template_redirect', 'woo_custom_redirect');

function woo_custom_redirect($redirect) {
    // HERE set your product category (can be term IDs, slugs or names)
    $category = 'subscription';

    $found = false;

    // CHECK CART ITEMS: search for items from our product category
    foreach(WC() - > cart - > get_cart() as $cart_item) {
            if (has_term($category, 'product_cat', $cart_item['product_id'])) {
                    $found = true;
                    break;
            }
    }

    if (!is_user_logged_in() && is_checkout() && $found) {
            wp_redirect(get_permalink(get_option('woocommerce_myaccount_page_id')));
            exit();
    }
}
2
  • Please,where i have to put this code? Thank you!! Dec 7 '20 at 12:46
  • Place this code in your child theme's functions.php file. p.s. All questions are best asked in the comments to my answer.
    – Dmitry
    Dec 7 '20 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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