• Resolved seifer1975

    (@seifer1975)


    Hello Support, I just want to ask how to add a product to the newly account created and based on a customers meta data product ID attached to them after registering. I found a code from the other support below but I wanted the $product_id = [specific customers meta-data product].

    How to achieve this?

    Thank you.

    <?php
    /*
    * Automatically adding the product to the cart.
    */
    function aaptc_add_product_to_cart() {
        if ( ! is_admin() ) {
            $product_id = 12986;  // Product Id of the free product which will get added to cart
            $found 	= false;
            //check if product already in cart
            if ( sizeof( WC()->cart->get_cart() ) > 0 ) {
                foreach ( WC()->cart->get_cart() as $cart_item_key => $values ) {
                    $_product = $values['data'];
                    if ( $_product->get_id() == $product_id )
                        $found = true;
                }
                // if product not found, add it
                if ( ! $found )
                    WC()->cart->add_to_cart( $product_id );
            } else {
                // if no products in cart, add it
                WC()->cart->add_to_cart( $product_id );
            }
        }    
    }
    add_action( 'init', 'aaptc_add_product_to_cart' );
    >?

    Apologies, the code above was when a customer visit the site a product will be automatically added to the cart.

    Is there a way to add a specific product to the account’s cart based on the meta-data when after the customer register?

    So that they can just login and see the item is on the cart when they selected when they where registering from the site.

    Thank you for the help.

    • This topic was modified 3 years, 5 months ago by seifer1975.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Adding Product to the Account After Registration’ is closed to new replies.