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!

1 Answer 1

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;

    if (!is_user_logged_in() && is_checkout() && $found) {
  • Please,where i have to put this code? Thank you!! Commented Dec 7, 2020 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
    Commented Dec 7, 2020 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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