• Resolved Emma

    (@emsieh)


    I’ve found and added the code to export Bookings start date and end date which works great, however is it possible to filter by these dates? Eg. I want to filter the export to only show Bookings start dates of tomorrow/on X date. I can’t find the field for it under ‘custom fields’.
    Thank you

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author algol.plus

    (@algolplus)

    Hello

    You won’t see booking fields as they save booking as separate record in database.

    You can upload booking plugin to https://algolplus.freshdesk.com/
    and I’ll try to find solution.

    thanks, Alex

    Thread Starter Emma

    (@emsieh)

    I’m just using the official WooCommerce Bookings plugin

    Plugin Author algol.plus

    (@algolplus)

    But it’s not free. I need fresh version .

    Plugin Author algol.plus

    (@algolplus)

    for whom having same problem.
    1.you should set booking start date in “Date Range” (1st field)
    2. open section “Misc Settings” and add following PHP code.
    thanks, Alex

    // you should set booking start date in "Date Range" (1st field)
    //remap settings
    add_filter('woe_settings_validate_defaults', function($settings){
        if($settings['from_date']) {
            $settings['book_start'] = date("Ymd", strtotime($settings['from_date']));
            $settings['from_date'] = "";
        }
        return $settings;
    });
    
    //filter orders
    add_filter( 'woe_sql_get_order_ids_where', function($where, $settings ){
        global $wpdb;
        $where[]= "orders.ID IN ( SELECT DISTINCT post_parent FROM {$wpdb->posts} WHERE ID IN (SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_booking_start' AND meta_value LIKE '{$settings['book_start']}%'))";
        return $where;
    },10,2);
    
    //filter order items
    add_filter( 'woe_skip_order_item', function($skip, $product, $item, $item_meta, $post ){
        global $wpdb;
        $booking_id = $wpdb->get_var( "SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key= '_booking_order_item_id' AND meta_value=" . intval( $item->get_id() ) );
        if( $booking_id ) {
            $book_start_time = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->postmeta} WHERE meta_key= '_booking_start' AND post_id=" . $booking_id );
            // it's string in format 20200601000000
            if( substr($book_start_time,0,8) !=WC_Order_Export_Engine::$current_job_settings['book_start'])
                $skip=true;
        }
        return $skip;
    },10,5);

    ?

    Thread Starter Emma

    (@emsieh)

    This works perfectly, thanks.

    This is great thanks for this, is there any way to order by time also via this filter? Or date and time if choosing multiple booking days (although we will only be exporting on a daily basis)

    Plugin Author algol.plus

    (@algolplus)

    I’m sorry, I can’t code this script, it’s too time-consuming.

    but you can try tweak SQL using filter “woe_sql_get_order_ids_order_by”

    • This reply was modified 4 years, 8 months ago by algol.plus.

    OK thanks for getting back to me about this, I shall try that out

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Filter by Bookings start date’ is closed to new replies.