woogc/network_orders/get_orders/mysql_query
17879
wp-singular,documentation-template-default,single,single-documentation,postid-17879,wp-theme-awake,wp-child-theme-awake-child,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.8,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-,wpb-js-composer js-comp-ver-8.1,vc_responsive
 

woogc/network_orders/get_orders/mysql_query

WP Global Cart / woogc/network_orders/get_orders/mysql_query
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

woogc/network_orders/get_orders/mysql_query

Name: woogc/network_orders/get_orders/mysql_query
Type: Filter
Arguments: $mysql_query

The woogc/network_orders/get_orders/mysql_query filter receives the raw MySQL query string that the WooGC network-orders routine will use to fetch orders across sites in a multisite environment. Use this filter to inspect or modify the final SQL before it is executed — for example to add/remove WHERE conditions, change ORDER BY / LIMIT, inject joins, or alter UNION members.

Below are two safe examples you can drop into wp-content/mu-plugins, or a plugin, or theme’s functions.php. Both examples modify the SQL so records with status draft are excluded in addition to the existing exclusion of trash. The first uses a regular expression (robust to spacing), the second uses a simple str_replace (works for exact-matching query snippets).


    add_filter( 'woogc/network_orders/get_orders/mysql_query', 'my_woogc_exclude_drafts_regex', 10, 1 );
    function my_woogc_exclude_drafts_regex( $sql ) 
        {
            // Quick check: if 'draft' already present in an exclusion, do nothing.
            // We look for "NOT IN(...draft..." to be conservative.
            if ( preg_match( "/NOT\s+IN\s*\([^)]*['\"]\s*draft\s*['\"]/i", $sql ) ) {
                return $sql;
            }

            // Replace any NOT IN('trash') or NOT IN( 'trash' ) (single or double quotes)
            // with NOT IN('trash','draft'). Pattern is case-insensitive and tolerant of spaces.
            $pattern = "/NOT\s+IN\s*\(\s*(['\"])trash\\s*\)/i";
            $replacement = "NOT IN('trash','wc-checkout-draft')";

            $modified = preg_replace( $pattern, $replacement, $sql );

            // If preg_replace returned null (error), fall back to original SQL
            if ( $modified === null ) {
                return $sql;
            }

            return $modified;
        }

Simple str_replace (works when the query contains exactly NOT IN(‘trash’))

    add_filter( 'woogc/network_orders/get_orders/mysql_query', 'my_woogc_exclude_drafts_strreplace', 10, 1 );
    function my_woogc_exclude_drafts_strreplace( $sql ) 
        {
            // Only replace the exact token NOT IN('trash') to avoid unexpected edits.
            // You can add more variants (with spaces) if needed.
            if ( strpos( $sql, "NOT IN('trash','draft')" ) !== false ) {
                return $sql; // already applied
            }

            return str_replace( "NOT IN('trash')", "NOT IN('trash','wc-checkout-draft')", $sql );
        }
0
Would love your thoughts, please comment.x
()
x