How to set cookie after payment and trial on pro-sites

I want to set TEST_COOKIE after pro sites signup and payment done, or signup as a trial. How can I achieve this?

  • Panos
    • SLS

    Hi Ben ,

    That cookie wordpress_test_cookie is created by wordpress when you navigate to the login screen and it is only used to check if cookies are allowed. So I'm not sure it's a good idea to rely on that cookie.

    However you can set it from the template_redirect hook for example:

    add_action( 'template_redirect', function(){
        if ( isset( $_COOKIE[TEST_COOKIE] ) ) {
            return;
        }
    
        if (
            isset( $_REQUEST['cc_stripe_checkout'] ) &&
            1 == $_REQUEST['cc_stripe_checkout'] &&
            isset( $_REQUEST['stripeToken'] ) &&
            isset( $_REQUEST['blog_name'] )
        ) {
    
            $blog_name = $_REQUEST['blog_name'];
            $blog_id = get_id_from_blogname( $blog_name );
    
            if ( ! is_pro_site( $blog_id ) && ! is_pro_trial( $blog_id ) ) {
                return;
            }
    
            $secure = ( 'https' === parse_url( wp_login_url(), PHP_URL_SCHEME ) );
            setcookie( TEST_COOKIE, 'WP Cookie check', 0, COOKIEPATH, COOKIE_DOMAIN, $secure );
            if ( SITECOOKIEPATH != COOKIEPATH ){
                setcookie( TEST_COOKIE, 'WP Cookie check', 0, SITECOOKIEPATH, COOKIE_DOMAIN, $secure );
            }
    
        }
    
    } );

    Hope this helps!
    Kind regards!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.