Search
Redirect to origin shop on Order Received, when using Single Checkout with Split - WP Global Cart
17040
documentation-template-default,single,single-documentation,postid-17040,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.0,eltd-smooth-scroll,eltd-smooth-page-transitions,eltd-mimic-ajax,eltd-grid-1200,eltd-blog-installed,eltd-default-style,eltd-fade-push-text-top,eltd-header-standard,eltd-sticky-header-on-scroll-down-up,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-menu-item-first-level-bg-color,eltd-dropdown-slide-from-top,eltd-,eltd-fullscreen-search eltd-search-fade,eltd-side-menu-slide-from-right,wpb-js-composer js-comp-ver-6.3.0,vc_responsive
 

Redirect to origin shop on Order Received, when using Single Checkout with Split

WP Global Cart / Redirect to origin shop on Order Received, when using Single Checkout with Split
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

Redirect to origin shop on Order Received, when using Single Checkout with Split

When utilizing the Single Checkout option, all products within the global cart undergo processing within a designated shop. Conversely, when opting for the Split function, individual orders are generated within each of the shops that contributed products to the cart.

Upon the completion of the checkout process, a page titled ‘Order Received’ is presented to the customer.

To seamlessly redirect the customer to the ‘Order Received’ page hosted on the shop where the origin product was located, you can make use of the following code snippet. Simply update the variable $ProductsOriginShop with the appropriate shop ID for redirection.

    global $ProductsOriginShop;
    $ProductsOriginShop    =   1;
    
    add_action('woocommerce_thankyou',  '__woocommerce_thankyou' );
    function __woocommerce_thankyou()
        {
            global ${"order-received"};
            
            $order_received =   ${"order-received"};
            
            if ( empty ( $order_received ) )
                return; 
            
            global $wpdb, $blog_id, $ProductsOriginShop, $WooGC;
            
            if ( $blog_id   ==  $ProductsOriginShop )
                return;  
            
            $WooGC->functions->remove_anonymous_object_filter('woocommerce_get_checkout_url', 'WooGC_Template',   'woocommerce_get_checkout_url',  999);
            
            $origin_blog_id =   $blog_id;
            
            switch_to_blog( $ProductsOriginShop );
            
            $mysql_query    =   $wpdb->prepare ( "SELECT PM.post_id from " . $wpdb->postmeta ." as PM
                                                        JOIN " . $wpdb->postmeta ." AS PM2 ON PM.post_id    =   PM2.post_id
                                                        WHERE PM.`meta_key`    =   'checkout_order_id'  and PM.`meta_value`    =   %s
                                                            AND PM2.`meta_key`    =   'checkout_blog_id'  and PM2.`meta_value`    =   %s", $order_received, $origin_blog_id );
            $remote_order_id = $wpdb->get_var( $mysql_query );
            
            $remote_order   =   new wc_order ( $remote_order_id );
            $order_received_url = wc_get_endpoint_url( 'order-received', $remote_order->get_id(), wc_get_checkout_url() );
            $order_received_url = add_query_arg( 'key', $remote_order->get_order_key(), $order_received_url );
            $order_received_url = add_query_arg( 'checkout_split_redirect', '1', $order_received_url );

            restore_current_blog();
            
            wp_redirect( $order_received_url );  
            
            die();
        }
    
    add_filter ( 'wp_loaded', '__wp_loaded' ) ;
    function __wp_loaded()
        {   
            global $WooGC;
            
            if ( isset ( $_GET['checkout_split_redirect'] ) &&  $_GET['checkout_split_redirect']    ==  '1' )
                $WooGC->functions->remove_anonymous_object_filter( 'wp', 'WooGC_Template',   'check_checkout_location' );
            
        }
0
Would love your thoughts, please comment.x
()
x