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 );
}