Filter orders
1 2 3 4 5 |
// export only orders with total > 10 add_filter( 'woe_order_export_started', function ( $order_id ) { $order = new WC_Order($order_id); return ($order->get_total() > 10.00) ? $order_id: false; }); |
1 2 3 4 5 6 7 8 9 |
// skip renewal orders generated by WooCommerce Subscription add_filter('woe_order_export_started', function($order_id){ if( !function_exists("wcs_order_contains_subscription") ) return $order_id; if( !wcs_order_contains_subscription($order_id,'renewal') ) return $order_id; else return false; }); |
1 2 3 4 5 6 7 8 |
//add refunds to order export add_filter( "woe_get_order_ids", function($ids) { global $wpdb; if(!$ids) return $ids; $ids_sql = join(",",$ids); $refunds = $wpdb->get_col("SELECT ID AS order_id FROM {$wpdb->prefix}posts WHERE post_type='shop_order_refund' AND post_parent in ($ids_sql) "); return array_merge($ids,$refunds); }); |
1 2 3 4 5 |
//export orders having non-empty customer notes add_filter( 'woe_sql_get_order_ids_where', function($where, $settings) { $where[] = " orders.post_excerpt<>'' "; return $where; },10,2); |
1 2 3 4 5 6 7 8 9 10 11 |
// replace {yesterday} and {today} with actual values comparison operators // tweak formats for your needs! add_filter('woe_settings_validate_defaults', function ($settings) { $settings = json_encode($settings); // to string $yesterday = date("Y-m-d" , strtotime("-1 day", current_time( 'timestamp' ) )); $settings = str_replace( '{yesterday}', $yesterday, $settings); $today = date("Y-m-d" , current_time( 'timestamp' ) ); $settings = str_replace( '{today}', $today, $settings); $settings = json_decode($settings, true); // to array return $settings; } ); |
1 2 3 4 5 6 7 8 |
// replace {current_user} with actual value in comparison operators add_filter('woe_settings_validate_defaults', function ($settings) { $settings = json_encode($settings); // to string $user_id = get_current_user_id(); $settings = str_replace( '{current_user}', $user_id, $settings); $settings = json_decode($settings, true); // to array return $settings; } ); |
1 2 3 4 5 6 7 |
//skip zero coupons add_filter( 'woe_fetch_order_coupon', function($row, $item, $item_meta) { if ( $item['discount_amount'] == 0 ) return false; else return $row; },10,4); |
1 2 3 4 5 6 7 |
// set custom time range in scheduled job // export orders starting from the last order of 19 of yesterday until 12 today add_filter('woe_settings_validate_defaults', function($settings) { $settings['from_date'] = date( "Y-m-d 19:00:00", strtotime( "-1 day",current_time("timestamp")) ); $settings['to_date'] = date( "Y-m-d 12:00:00", current_time("timestamp")); return $settings; }); |
1 2 3 4 |
//export pending orders by Status Change job add_action( 'woocommerce_checkout_order_processed', function($order_id, $posted_data, $order ){ do_action("woocommerce_order_status_changed",$order_id,"","wc-pending"); },10,3); |