Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Appointment › Synchro all calendars and filter by date and price
- This topic has 4 replies, 2 voices, and was last updated 5 years, 2 months ago by m.loreaux.
- AuthorPosts
- September 22, 2019 at 9:39 pm #82988m.loreauxParticipant
Hi,
Firstly thanks for these plugins they are really top for what I’m looking to do.
I use the plugin woocommerce appointment and would like to know if there is a solution to synchronize the calendars of all products set up by the seller?
And what is there a solution to put in the filters, filtering by date and by price? As that provides in the plugin WooCommerce appointment
Thx
- September 24, 2019 at 9:54 am #83331WCFM ForumMember
Hi,
You are welcome 🙂
Well, all these works as per WC Appointments plugin’s default behavior.
Thank You
- September 25, 2019 at 4:03 am #83500m.loreauxParticipant
Hi,
Ok I did Because the synchronization did not work. So for synchronization between the calendars of products from a vendor :
add_action( ‘woocommerce_order_status_processing’, ‘woocommerce_order_add_all_synchro_appointment’, 10, 1 );
add_action( ‘woocommerce_order_status_completed’, ‘woocommerce_order_add_all_synchro_appointment’, 10, 1 );
function woocommerce_order_add_all_synchro_appointment( $order ) {
global $wpdb, $WCFM;$order = wc_get_order($order);
foreach( $order->get_items() as $item_id => $item ){
$product_id = $item->get_product_id();
$vendor_id = wcfm_get_vendor_id_by_post( $product_id );
$products_objs = $WCFM->wcfm_vendor_support->wcfm_get_products_by_vendor( $vendor_id );$appointment_id = WC_Appointment_Data_Store::get_appointment_ids_from_order_item_id( $item_id );
$appointment = new WC_Appointment( $appointment_id[0] );$date_time_start = explode(“,”, $appointment->get_start_date(“Y-m-d”, “, H:i”));
$date_time_end = explode(“,”, $appointment->get_end_date(“Y-m-d”, “, H:i”));
$date_start = $date_time_start[0];
$date_end = $date_time_end[0];
$time_start = $date_time_start[1];
$time_end = $date_time_end[1];foreach($products_objs as $product_obj){
$is_exist = $wpdb->get_row(
$wpdb->prepare(
“SELECT ID
FROM {$wpdb->prefix}wc_appointments_availability
WHEREkind_id
= %d
AND from_range = %s
AND to_range = %s
AND from_date = %s
AND to_date = %s”,
$product_obj->ID, $time_start, $time_end, $date_start, $date_end
),
OBJECT
);if(empty($is_exist)){
$wpdb->insert(
$wpdb->prefix . ‘wc_appointments_availability’,
array(
‘kind’ => ‘availability#product’,
‘kind_id’ => $product_obj->ID,
‘title’ => ”,
‘range_type’ => “custom:daterange”,
‘from_range’ => $time_start,
‘to_range’ => $time_end,
‘from_date’ => $date_start,
‘to_date’ => $date_end,
‘appointable’ => “no”,
‘priority’ => “1”,
‘ordering’ => “0”,
‘rrule’ => “”,
‘date_created’ => current_time( ‘mysql’ ),
‘date_modified’ => current_time( ‘mysql’ ),
)
);
}}
}}
add_action( ‘woocommerce_order_status_cancelled’, ‘woocommerce_order_delete_synchro_appointment’, 10, 1 );
add_action( ‘woocommerce_order_status_refunded’, ‘woocommerce_order_delete_synchro_appointment’, 10, 1 );
add_action( ‘woocommerce_order_status_failed’, ‘woocommerce_order_delete_synchro_appointment’, 10, 1 );
add_action( ‘woocommerce_trash_order’, ‘woocommerce_order_delete_synchro_appointment’, 10, 1 );
add_action( ‘woocommerce_delete_order’, ‘woocommerce_order_delete_synchro_appointment’, 10, 1 );
function woocommerce_order_delete_synchro_appointment( $order ) {
global $wpdb, $WCFM;$order = wc_get_order($order);
foreach( $order->get_items() as $item_id => $item ){
$product_id = $item->get_product_id();
$vendor_id = wcfm_get_vendor_id_by_post( $product_id );
$products_objs = $WCFM->wcfm_vendor_support->wcfm_get_products_by_vendor( $vendor_id );$appointment_id = WC_Appointment_Data_Store::get_appointment_ids_from_order_item_id( $item_id );
$appointment = new WC_Appointment( $appointment_id[0] );$date_time_start = explode(“,”, $appointment->get_start_date(“Y-m-d”, “, H:i”));
$date_time_end = explode(“,”, $appointment->get_end_date(“Y-m-d”, “, H:i”));
$date_start = $date_time_start[0];
$date_end = $date_time_end[0];
$time_start = $date_time_start[1];
$time_end = $date_time_end[1];foreach($products_objs as $product_obj){
$wpdb->delete(
$wpdb->prefix . ‘wc_appointments_availability’,
array(
‘kind’ => ‘availability#product’,
‘kind_id’ => $product_obj->ID,
‘range_type’ => “custom:daterange”,
‘from_range’ => $time_start,
‘to_range’ => $time_end,
‘from_date’ => $date_start,
‘to_date’ => $date_end,
‘appointable’ => “no”,
‘priority’ => “1”,
)
);
}
}
} - September 26, 2019 at 2:24 pm #83756WCFM ForumMember
Hi,
Is this code working for you and fulfill your requirement?
Actually, this code is for “Availability Manage”, not for calendar sync!
Thank You
- September 27, 2019 at 6:18 pm #84045m.loreauxParticipant
Hi
Yes he do.
When I talk sync between calendars, it’s with the reservation calendars in a product, with the woocommerce appointment plugin
- AuthorPosts
- The topic ‘Synchro all calendars and filter by date and price’ is closed to new replies.