Skip to:
Content
Pages
Categories
Search
Top
Bottom

Send message after Woocommerce checkout


  • King Ding
    Participant

    @dazzerr

    I’ve created a function that sends a message to the current user after checking out with a woocommerce product. However, this only works if the user already has an account prior to checking out. Users of my website cannot create an account prior to checkout though, they must create their account at the checkout.

    I’ve tried hooks such as:

    user_register
    register_new_user
    woocommerce_order_status_completed

    But none of them have worked for me 🙁

    Here is my code if you have an alternative suggestion. Thanks!

    function send_message_to_new_member( $user_id) {
    		
            $current_user = get_current_user_id();
            $current_user_name = wp_get_current_user();
        
            $args = array(
                'sender_id' => 1,
                'thread_id' => false,
                'recipients' => $current_user,
                'subject' => 'Welcome!',
                'content' => sprintf( __( 'Hey %1$s, here is my message' ), $current_user_name->user_firstname ),
                'date_sent' => bp_core_current_time()
            );
    
            $result = messages_new_message( $args );
    }
    add_action( 'user_register', 'send_message_to_new_member' );
  • You must be logged in to reply to this topic.
Skip to toolbar