Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'wcfm_order_status_condition', function($conditions, $table_handler) {
- global $WCFMmp;
- remove_filter( 'wcfm_order_status_condition', array( $WCFMmp->wcfmmp_vendor, 'wcfmmp_vendor_order_status_condition' ), 10 );
- //Get all booking products of the vendor
- $product_args = array(
- 'limit' => -1,
- 'status' => array( 'draft', 'pending', 'publish', 'private', 'scheduled' ),
- 'type' => 'booking',
- 'author' => $WCFMmp->vendor_id,
- 'return' => 'ids',
- );
- $products = wc_get_products($product_args);
- //Get all bookings
- $args = array(
- 'numberposts' => -1,
- 'post_type' => 'wc_booking',
- 'post_status' => 'complete',
- 'meta_query' => array(
- array(
- 'key' => '_booking_product_id',
- 'value' => $products,
- 'compare' => 'IN',
- )
- ),
- 'date_query' => array(
- 'after' => date('Y-m-d', strtotime('-15 days'))
- ),
- 'fields' => 'ids',
- );
- $booking_ids = get_posts($args);
- $order_item_ids = array();
- foreach($booking_ids as $booking_id) {
- $booking = get_wc_booking($booking_id);
- if($booking) {
- $order_item_ids[] = $booking->get_order_item_id();
- }
- }
- $conditions = array();
- if(!empty($order_item_ids)) {
- $conditions[] = "{$table_handler}.item_id IN ('" . implode( "','", $order_item_ids ) . "')";
- }
- $wcfmmp_marketplace_options = wcfm_get_option( 'wcfm_marketplace_options', array() );
- $order_sync = isset( $wcfmmp_marketplace_options['order_sync'] ) ? $wcfmmp_marketplace_options['order_sync'] : 'no';
- $status = get_wcfm_marketplace_active_withdrwal_order_status_in_comma();
- if( $order_sync == 'yes' ) {
- $conditions[] = "{$table_handler}.order_status IN ({$status})";
- } else {
- $conditions[] = "{$table_handler}.commission_status IN ({$status})";
- }
- return ' AND ( ' . implode(' OR ', $conditions) . ' )';
- }, 9, 2 );
- add_filter('wcfm_schedule_period_starts_from', function( $period_starts_from, $withdrawal_schedule ) {
- if($withdrawal_schedule === 'month') {
- $now = strtotime('now');
- $mid_of_month = strtotime('first day of this month') + 86400 * 14;
- $next_month = strtotime('first day of next month');
- if($now > $mid_of_month) {
- return $next_month;
- } else {
- return $mid_of_month;
- }
- }
- return $period_starts_from;
- }, 10, 2);
- add_filter('wcfm_schedule_period_interval', function( $period_interval, $withdrawal_schedule ) {
- if($withdrawal_schedule === 'month') {
- $now = strtotime('now');
- $mid_of_month = strtotime('first day of this month') + 86400 * 14;
- $next_month = strtotime('first day of next month');
- if($now > $mid_of_month) {
- return 14;
- } else {
- return ( $next_month - $mid_of_month ) / 86400;
- }
- }
- return $period_interval;
- }, 10, 2);
- add_action('action_scheduler_after_execute', function($action_id, $action, $context) {
- if($action->get_hook() === 'wcfmmp_withdrawal_periodic_scheduler' ) {
- if( !get_option( 'wcfmmp_withdrawal_periodic_scheduler_reset' ) ) {
- update_option( 'wcfmmp_withdrawal_periodic_scheduler_reset', 1 );
- }
- }
- }, 10, 3);
- add_action( 'wcfm_init', function() {
- if( get_option( 'wcfmmp_withdrawal_periodic_scheduler_reset' ) ) {
- $today = date('j');
- if( $today > 1 && $today < 15 || $today > 15 && $today < 29 ) {
- $next = WC()->queue()->get_next( 'wcfmmp_withdrawal_periodic_scheduler' );
- if($next) {
- WC()->queue()->cancel_all( 'wcfmmp_withdrawal_periodic_scheduler' );
- }
- delete_option( 'wcfmmp_withdrawal_periodic_scheduler_reset');
- }
- }
- }, 20 );
Add Comment
Please, Sign In to add comment