woocommerce-to-zoom-meetings.php
add-meeting-registrant.php
<?php
// add_action( ‘woocommerce_checkout_update_order_meta’, ‘woocommerce_to_zoom_meetings_add_registrant’,999);
add_action( ‘woocommerce_order_status_completed’, ‘woocommerce_to_zoom_meetings_add_registrant’,0 );
function woocommerce_to_zoom_meetings_add_registrant( $order_id ) {
//start WooCommerce logging
$logger = wc_get_logger();
$context = array( ‘source’ => ‘woocommerce-to-zoom-meetings’ );
$logger->info( ‘STARTING PROCESSING ORDER: ‘.$order_id, $context );
//get order object inc ase we need it
$order = new WC_Order( $order_id );
//get the metadata for the order
$all_post_meta = get_post_meta($order_id);
foreach($all_post_meta as $meta_key => $meta_value){
//only proceed for keys which contain zoom_meeting
if (strpos($meta_key, ‘zoom_meeting’) !== false) {
//key looks like: zoom_meeting-217072930-1
$key_exploded = explode(‘-‘,$meta_key);
$meeting_id = $key_exploded[1];
$logger->info( ‘Meeting ID: ‘.$meeting_id, $context );
//if meeting id is bookable product then lets crate the meeting first in Zoom Meetings
//by checking if $woocommerce_booking_meeting_id is not set it prevents multiple meetings from being created
if(strpos($meeting_id, ‘WooCommerce_Bookings’) !== false && !isset($woocommerce_booking_meeting_id)){
$logger->info( ‘We are going to try to create a meeting in Zoom as this is a bookable product’, $context );
if ( is_callable( ‘WC_Booking_Data_Store::get_booking_ids_from_order_id’) ) {
$booking_data = new WC_Booking_Data_Store();
$booking_ids = $booking_data->get_booking_ids_from_order_id( $order_id );
foreach($booking_ids as $booking_id){
if (class_exists( ‘sitepress’ ) && (apply_filters( ‘wpml_post_language_details’, NULL, $booking_id )[‘language_code’] != $all_post_meta[‘wpml_language’][0])) {
continue;
}
$booking_start = get_post_meta($booking_id, ‘_booking_start’, true); //20200417070000
$booking_end = get_post_meta($booking_id, ‘_booking_end’, true); //2020 04 17 08 00 00
//we need to convert date times like 20200417070000 to 2020-03-31T12:02:00Z
$booking_start_year = substr($booking_start,0,4);
$booking_start_month = substr($booking_start,4,2);
$booking_start_day = substr($booking_start,6,2);
$booking_start_hour = substr($booking_start,8,2);
$booking_start_minute = substr($booking_start,10,2);
$booking_start_second = substr($booking_start,12,2);
$booking_start_nice = $booking_start_year.’-‘.$booking_start_month.’-‘.$booking_start_day.’T’.$booking_start_hour.’:’.$booking_start_minute.’:’.$booking_start_second;
$booking_end_year = substr($booking_end,0,4);
$booking_end_month = substr($booking_end,4,2);
$booking_end_day = substr($booking_end,6,2);
$booking_end_hour = substr($booking_end,8,2);
$booking_end_minute = substr($booking_end,10,2);
$booking_end_second = substr($booking_end,12,2);
$booking_end_nice = $booking_end_year.’-‘.$booking_end_month.’-‘.$booking_end_day.’T’.$booking_end_hour.’:’.$booking_end_minute.’:’.$booking_end_second;
//now we need to work out the agenda
$booking_start_timestamp = strtotime($booking_start_nice);
$booking_end_timestamp = strtotime($booking_end_nice);
$duration = round(abs($booking_end_timestamp – $booking_start_timestamp) / 60,2);
//get other order details
$billing_first_name = $order->get_billing_first_name();
$billing_last_name = $order->get_billing_last_name();
$billing_full_name = $billing_first_name.’ ‘.$billing_last_name;
//we need to get the product title and description
$items = $order->get_items();
foreach ( $items as $item ) {
$product_id = $item->get_product_id();
$meeting_selection = get_post_meta($product_id,’zoom_meeting_selection’,true);
// $logger->info( ‘PRODUCT ID FOUND: ‘.$product_id.’ MEETING SELECTION: ‘.$meeting_selection, $context );
if(strpos($meeting_selection, ‘WooCommerce Bookings’) !== false){
// $logger->info( ‘I WAS RAN’, $context );
$product_title = get_the_title($product_id).’ (‘.$billing_full_name.’)’; // we will put the billing name in the meeting to make it more identifiable
$product_description = wp_strip_all_tags(get_the_content(null,false,$product_id));
$product_description = trim(preg_replace(‘/\s+/’, ‘ ‘, $product_description));
$product_description = substr($product_description, 0, 1999);
}
}
//lets get the user id for the meeting
$user_id = explode(‘WooCommerce_Bookings’,$meeting_id);
if( strlen($user_id[1]) > 1 && $user_id[1] != ‘me’){
$user_id = $user_id[1];
} else {
$user_id = ‘me’;
}
//lets actually create the meeting
//register the person for the webinar
$url = woocommerce_to_zoom_meetings_get_api_base().’users/’.$user_id.’/meetings’;
$access_token = woocommerce_to_zoom_meetings_get_access_token();
$data = array(
‘topic’ => $product_title,
‘type’ => 2,
‘start_time’ => $booking_start_nice,
‘duration’ => $duration,
‘timezone’ => get_option(‘timezone_string’),
‘agenda’ => $product_description,
‘settings’ => array(
‘use_pmi’ => ‘false’,
‘approval_type’ => 0,
‘audio’ => ‘both’,
‘show_share_button’ => ‘true’,
‘allow_multiple_devices’ => ‘true’,
),
);
$response = wp_remote_post( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.$access_token,
‘Content-Type’ => ‘application/json; charset=utf-8’,
),
‘body’ => json_encode($data),
));
$logger->info( ‘URL: ‘.$url.’ DATA: ‘.json_encode($data).’ ACCESSTOKEN: ‘. $access_token , $context);
$status = wp_remote_retrieve_response_code( $response );
if($status == 201){
//do something
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$woocommerce_booking_meeting_id = $decodedBody[‘id’];
$logger->info( ‘NEW MEETING ID: ‘.$woocommerce_booking_meeting_id, $context);
} else {
$logger->info( ‘SOMETHING WENT WRONG, STATUS: ‘.$status, $context);
}
}
}
}
if(isset($woocommerce_booking_meeting_id)){
$meeting_id = $woocommerce_booking_meeting_id;
}
// $logger->info( ‘CHECK ME: ‘.$meeting_id, $context);
$meta_value = get_post_meta($order_id,$meta_key,true);
//if there’s language data from WPML, add the language to the meta
if( metadata_exists(‘post’, $order_id, ‘wpml_language’) ){
//get the language of the order
$wpml_language = get_post_meta( $order_id, ‘wpml_language’, true ); //this will be like en for english
//create a translation array
$language_translation = array(
‘en’ => ‘en-US’,
‘de’ => ‘de-DE’,
‘es’ => ‘es-ES’,
‘fr’ => ‘fr-FR’,
‘jp’ => ‘jp-JP’,
‘pt’ => ‘pt-PT’,
‘ru’ => ‘ru-RU’,
‘zh’ => ‘zh-CN’,
‘ko’ => ‘ko-KO’,
‘it’ => ‘it-IT’,
‘vi-VN’ => ‘VN’,
‘pl’ => ‘pl-PL’,
‘Tr’ => ‘Tr-TR’,
);
//check if language is in our translation array
if( array_key_exists($wpml_language, $language_translation) ){
$new_language = $language_translation[$wpml_language];
} else {
//do a default language
$new_language = ‘en-US’;
}
//add the language to our meta array
$meta_value[‘language’] = $new_language;
}
$body_data_to_json = json_encode($meta_value);
//register the person for the webinar
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$meeting_id.’/registrants’;
//prevent getting the access token twice in quick succession
if(!isset($access_token)){
$access_token = woocommerce_to_zoom_meetings_get_access_token();
}
$response = wp_remote_post( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.$access_token,
‘Content-Type’ => ‘application/json; charset=utf-8’,
),
‘body’ => $body_data_to_json,
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 201){
//do something
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$registrant_id = $decodedBody[‘registrant_id’];
$join_url = $decodedBody[‘join_url’];
// $participant_pin_code = $decodedBody[‘participant_pin_code’];
//lets add meta to the order id
if(get_post_meta($order_id,’zoom_meetings_registrant_ids’,false)){
$existing_registrants = get_post_meta($order_id,’zoom_meetings_registrant_ids’,true);
$existing_registrants[$registrant_id] = array(
‘first_name’ => $meta_value[‘first_name’],
‘last_name’ => $meta_value[‘last_name’],
‘email’ => $meta_value[‘email’],
‘join_url’ => $join_url,
‘meeting_id’ => $meeting_id,
// ‘participant_pin_code’ => $participant_pin_code,
);
update_post_meta( $order_id, ‘zoom_meetings_registrant_ids’, $existing_registrants );
} else {
update_post_meta( $order_id, ‘zoom_meetings_registrant_ids’, array($registrant_id => array(
‘first_name’ => $meta_value[‘first_name’],
‘last_name’ => $meta_value[‘last_name’],
‘email’ => $meta_value[‘email’],
‘join_url’ => $join_url,
‘meeting_id’ => $meeting_id,
// ‘participant_pin_code’ => $participant_pin_code,
)));
}
//we are also going to add an action so people can do other things
do_action( ‘zoom_meetings_registrant_added’, $meta_value[‘first_name’], $meta_value[‘last_name’],$meta_value[‘email’], $join_url, $meeting_id,$order_id);
//we are also going to send the user an email if enabled in the settings
$registrant_email_enabled = get_option(‘wc_settings_zoom_meetings_enable_registrant_email’);
if(isset($registrant_email_enabled) && $registrant_email_enabled == ‘yes’){
//we need to do an api request to get the meeting data for the purpose of the email
//ideally we could get this above but when someone is buying an exisitng meeting we don’t have the name or time of the meeting we just have the id
//$meeting_id
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$meeting_id;
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.$access_token,
‘Content-Type’ => ‘application/json; charset=utf-8’,
),
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
//get response
$decoded_body = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$topic= $decoded_body[‘topic’];
$start_time = $decoded_body[‘start_time’];
$time_zone = $decoded_body[‘timezone’];
$password = $decoded_body[‘password’];
$date = new DateTime($start_time, new DateTimeZone(‘UTC’));
$date->setTimezone(new DateTimeZone($time_zone));
$meeting_date = $date->format(get_option( ‘date_format’ ));
$meeting_time = $date->format(get_option( ‘time_format’ ));
//lets get the subject and content
$subject = get_option(‘wc_settings_zoom_meetings_registrant_email_subject’);
$content = get_option(‘wc_settings_zoom_meetings_registrant_email_content’);
//lets only proceed if both the subject and content have content!
if(strlen($subject)>0 && strlen($content)>0){
//lets get all the variables
$shortcodes_list = array(
‘[registrant-first-name]’ => $meta_value[‘first_name’],
‘[registrant-last-name]’ => $meta_value[‘last_name’],
‘[registrant-email]’ => $meta_value[‘email’],
‘[registrant-join-link]’ => ‘<a href=»‘.$join_url.'» target=»_blank»>’.$join_url.'</a>’,
‘[meeting-passcode]’ => $password,
‘[meeting-name]’ => $topic,
‘[meeting-date]’ => $meeting_date,
‘[meeting-time]’ => $meeting_time,
‘[meeting-id]’ => $meeting_id,
);
//lets start with the subject
foreach($shortcodes_list as $shortcode => $replacement){
$subject = str_replace($shortcode,$replacement,$subject);
}
//now do the content
foreach($shortcodes_list as $shortcode => $replacement){
$content = str_replace($shortcode,$replacement,$content);
}
//lets send the email
$headers = array(‘Content-Type: text/html; charset=UTF-8’);
wp_mail( $meta_value[‘email’], $subject, $content, $headers );
}
}
}
} else {
//something bad happened
$logger->info(‘URL: ‘.$url,$context);
$logger->info(‘BODY: ‘.$body_data_to_json,$context);
$logger->info(‘ACCESS TOKEN: ‘.$access_token,$context);
$logger->info(‘STATUS: ‘.$status,$context);
if(is_array($response) && array_key_exists(‘body’,$response)){
$logger->info(‘RETURN BODY: ‘.$response[‘body’],$context);
}
do_action( ‘zoom_meetings_registrant_added_failure’, $meta_value[‘first_name’], $meta_value[‘last_name’],$meta_value[‘email’], $meeting_id,$order_id, $status );
}
}
}
//we are also going to add an action so people can do other things
do_action( ‘zoom_meetings_finished_processing_order’, $order_id);
}
/**
*
*
*
* Register someone for a recording
*/
add_action( ‘woocommerce_order_status_completed’, ‘woocommerce_to_zoom_recordings_add_registrant’,0 );
function woocommerce_to_zoom_recordings_add_registrant( $order_id ) {
//start WooCommerce logging
$logger = wc_get_logger();
$context = array( ‘source’ => ‘woocommerce-to-zoom-meetings’ );
$logger->info( ‘STARTING PROCESSING ORDER: ‘.$order_id, $context );
//get order object inc ase we need it
$order = new WC_Order( $order_id );
//get the metadata for the order
$all_post_meta = get_post_meta($order_id);
foreach($all_post_meta as $meta_key => $meta_value){
//only proceed for keys which contain zoom_meeting
if (strpos($meta_key, ‘zoom_recording’) !== false) {
//key looks like: zoom_meeting-217072930-1
$key_exploded = explode(‘-‘,$meta_key);
$recording_id = $key_exploded[1];
$key_exploded = explode(‘|’,$recording_id);
$recording_id = $key_exploded[0];
$logger->info( ‘Recording ID: ‘.$recording_id, $context );
$meta_value = get_post_meta($order_id,$meta_key,true);
//if there’s language data from WPML, add the language to the meta
if( metadata_exists(‘post’, $order_id, ‘wpml_language’) ){
//get the language of the order
$wpml_language = get_post_meta( $order_id, ‘wpml_language’, true ); //this will be like en for english
//create a translation array
$language_translation = array(
‘en’ => ‘en-US’,
‘de’ => ‘de-DE’,
‘es’ => ‘es-ES’,
‘fr’ => ‘fr-FR’,
‘jp’ => ‘jp-JP’,
‘pt’ => ‘pt-PT’,
‘ru’ => ‘ru-RU’,
‘zh’ => ‘zh-CN’,
‘ko’ => ‘ko-KO’,
‘it’ => ‘it-IT’,
‘vi-VN’ => ‘VN’,
‘pl’ => ‘pl-PL’,
‘Tr’ => ‘Tr-TR’,
);
//check if language is in our translation array
if( array_key_exists($wpml_language, $language_translation) ){
$new_language = $language_translation[$wpml_language];
} else {
//do a default language
$new_language = ‘en-US’;
}
//add the language to our meta array
$meta_value[‘language’] = $new_language;
}
$body_data_to_json = json_encode($meta_value);
//register the person for the webinar
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$recording_id.’/recordings/registrants’;
//prevent getting the access token twice in quick succession
if(!isset($access_token)){
$access_token = woocommerce_to_zoom_meetings_get_access_token();
}
$response = wp_remote_post( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.$access_token,
‘Content-Type’ => ‘application/json; charset=utf-8’,
),
‘body’ => $body_data_to_json,
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 201){
//do something
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$registrant_id = $decodedBody[‘registrant_id’];
$join_url = $decodedBody[‘share_url’];
// $participant_pin_code = $decodedBody[‘participant_pin_code’];
//lets add meta to the order id
if(get_post_meta($order_id,’zoom_meetings_registrant_ids’,false)){
$existing_registrants = get_post_meta($order_id,’zoom_meetings_registrant_ids’,true);
$existing_registrants[$registrant_id] = array(
‘first_name’ => $meta_value[‘first_name’],
‘last_name’ => $meta_value[‘last_name’],
‘email’ => $meta_value[‘email’],
‘join_url’ => $join_url,
‘meeting_id’ => $recording_id,
// ‘participant_pin_code’ => $participant_pin_code,
);
update_post_meta( $order_id, ‘zoom_meetings_registrant_ids’, $existing_registrants );
} else {
update_post_meta( $order_id, ‘zoom_meetings_registrant_ids’, array($registrant_id => array(
‘first_name’ => $meta_value[‘first_name’],
‘last_name’ => $meta_value[‘last_name’],
‘email’ => $meta_value[‘email’],
‘join_url’ => $join_url,
‘meeting_id’ => $recording_id,
// ‘participant_pin_code’ => $participant_pin_code,
)));
}
//we are also going to add an action so people can do other things
//we wont change this for recordings
do_action( ‘zoom_meetings_registrant_added’, $meta_value[‘first_name’], $meta_value[‘last_name’],$meta_value[‘email’], $join_url, $recording_id,$order_id);
//we are also going to send the user an email if enabled in the settings
$registrant_email_enabled = get_option(‘wc_settings_zoom_meetings_enable_registrant_email’);
if(isset($registrant_email_enabled) && $registrant_email_enabled == ‘yes’){
//we need to do an api request to get the meeting data for the purpose of the email
//ideally we could get this above but when someone is buying an exisitng meeting we don’t have the name or time of the meeting we just have the id
//$meeting_id
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$recording_id.’/recordings’;
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.$access_token,
‘Content-Type’ => ‘application/json; charset=utf-8’,
),
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
//get response
$decoded_body = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$topic= $decoded_body[‘topic’];
$start_time = $decoded_body[‘start_time’];
$time_zone = $decoded_body[‘timezone’];
$password = $decoded_body[‘password’];
$date = new DateTime($start_time, new DateTimeZone(‘UTC’));
$date->setTimezone(new DateTimeZone($time_zone));
$meeting_date = $date->format(get_option( ‘date_format’ ));
$meeting_time = $date->format(get_option( ‘time_format’ ));
//lets get the subject and content
$subject = get_option(‘wc_settings_zoom_meetings_registrant_email_subject’);
$content = get_option(‘wc_settings_zoom_meetings_registrant_email_content’);
//lets only proceed if both the subject and content have content!
if(strlen($subject)>0 && strlen($content)>0){
//lets get all the variables
$shortcodes_list = array(
‘[registrant-first-name]’ => $meta_value[‘first_name’],
‘[registrant-last-name]’ => $meta_value[‘last_name’],
‘[registrant-email]’ => $meta_value[‘email’],
‘[registrant-join-link]’ => ‘<a href=»‘.$join_url.'» target=»_blank»>’.$join_url.'</a>’,
‘[meeting-passcode]’ => $password,
‘[meeting-name]’ => $topic,
‘[meeting-date]’ => $meeting_date,
‘[meeting-time]’ => $meeting_time,
‘[meeting-id]’ => $meeting_id,
);
//lets start with the subject
foreach($shortcodes_list as $shortcode => $replacement){
$subject = str_replace($shortcode,$replacement,$subject);
}
//now do the content
foreach($shortcodes_list as $shortcode => $replacement){
$content = str_replace($shortcode,$replacement,$content);
}
//lets send the email
$headers = array(‘Content-Type: text/html; charset=UTF-8’);
wp_mail( $meta_value[‘email’], $subject, $content, $headers );
}
}
}
} else {
//something bad happened
$logger->info(‘URL: ‘.$url,$context);
$logger->info(‘BODY: ‘.$body_data_to_json,$context);
$logger->info(‘ACCESS TOKEN: ‘.$access_token,$context);
$logger->info(‘STATUS: ‘.$status,$context);
if(is_array($response) && array_key_exists(‘body’,$response)){
$logger->info(‘RETURN BODY: ‘.$response[‘body’],$context);
}
do_action( ‘zoom_meetings_registrant_added_failure’, $meta_value[‘first_name’], $meta_value[‘last_name’],$meta_value[‘email’], $recording_id,$order_id, $status );
}
}
}
}
add_action( ‘wp_ajax_zoom_meetings_register_user’, ‘woocommerce_to_zoom_meetings_add_registrant_from_form’ );
add_action( ‘wp_ajax_nopriv_zoom_meetings_register_user’, ‘woocommerce_to_zoom_meetings_add_registrant_from_form’ );
function woocommerce_to_zoom_meetings_add_registrant_from_form(){
$meeting_id = $_POST[‘meetingId’];
$json = stripslashes($_POST[‘json’]);
// echo ‘ERROR’;
// wp_die();
// $data = json_decode($json,true);
//register the person for the webinar
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$meeting_id.’/registrants’;
$access_token = woocommerce_to_zoom_meetings_get_access_token();
$response = wp_remote_post( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.$access_token,
‘Content-Type’ => ‘application/json; charset=utf-8’,
),
‘body’ => $json,
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 201){
$json_as_array = json_decode($json, true);
do_action( ‘zoom_meetings_registrant_added_non_woocommerce’, $json_as_array[‘first_name’], $json_as_array[‘last_name’],$json_as_array[‘email’], $meeting_id);
//registration page
$thank_you_page = get_option(‘wc_settings_zoom_meetings_thank_you_page’);
if(strlen($thank_you_page)>0){
$thank_you_page_link = get_permalink( $thank_you_page );
} else {
$thank_you_page_link = get_home_url();
}
echo $thank_you_page_link;
} else {
$json_as_array = json_decode($json, true);
echo ‘ERROR’;
do_action( ‘zoom_meetings_registrant_added_failure’, $json_as_array[‘first_name’], $json_as_array[‘last_name’],$json_as_array[‘email’], $meeting_id,false, $status );
}
wp_die();
}
?>
authentication.php
<?php
/**
*
*
*
* Get client ID
*/
function woocommerce_to_zoom_meetings_get_client_id() {
$sandbox_mode_setting = get_option(‘wc_settings_zoom_meetings_sandbox_mode’);
if(isset($sandbox_mode_setting) && $sandbox_mode_setting == ‘yes’){
$clientId = ‘rLjwXmDhRyKJDqt1AMhIAA’; //development
} else {
$clientId = ‘9eHIPv9TTrWh7JgciptoKw’;
}
return $clientId;
}
/**
*
*
*
* Get redirect URI
*/
function woocommerce_to_zoom_meetings_get_redirect_uri() {
$redirect_uri = ‘https://northernbeacheswebsites.com.au/redirectzoom/’;
return $redirect_uri;
}
/**
*
*
*
* Get authorisation
*/
function woocommerce_to_zoom_meetings_get_authorisation() {
$clientId = woocommerce_to_zoom_meetings_get_client_id();
$sandbox_mode_setting = get_option(‘wc_settings_zoom_meetings_sandbox_mode’);
if(isset($sandbox_mode_setting) && $sandbox_mode_setting == ‘yes’){
$clientSecret = ‘KVSkmbAV680M4wqFz5AqYUmttF6ZY4Id’; //development
} else {
$clientSecret = ‘GKuyYKqpbjp7ukdlXAvcliIJuenaDfiZ’;
}
return base64_encode($clientId.’:’.$clientSecret);
}
/**
*
*
*
* Get API base URL
*/
function woocommerce_to_zoom_meetings_get_api_base() {
$api_base = ‘https://api.zoom.us/v2/’;
return $api_base;
}
/**
*
*
*
* Save authentication details
*/
add_action( ‘wp_ajax_save_authentication_details_zoom_meetings’, ‘woocommerce_to_zoom_meetings_save_authentication_details’ );
function woocommerce_to_zoom_meetings_save_authentication_details() {
//get board name from ajax call
$code = $_POST[‘code’];
$url = ‘https://zoom.us/oauth/token’;
// $url .= ‘?grant_type=authorization_code’;
// $url .= ‘&code=’.$code;
// $url .= ‘&redirect_uri=’.woocommerce_to_zoom_meetings_get_redirect_uri();
//get access token
$response = wp_remote_post($url , array(
‘headers’ => array(
‘Authorization’ => ‘Basic ‘.woocommerce_to_zoom_meetings_get_authorisation(),
‘Content-Type’ => ‘application/x-www-form-urlencoded; charset=utf-8’,
),
‘body’ => array(
‘code’ => $code,
‘grant_type’ => ‘authorization_code’,
‘redirect_uri’ => woocommerce_to_zoom_meetings_get_redirect_uri(),
),
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
//decode the response and get the variables
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$refresh_token = $decodedBody[‘refresh_token’];
//update the options with the result
update_option(‘wc_settings_zoom_refresh_token’, $refresh_token);
// echo ‘SUCCESS’;
} else {
// echo ‘ERROR’;
}
echo $status;
//die
wp_die();
}
/**
*
*
*
* Get access token – enable to be overrided
*/
if( !function_exists(‘woocommerce_to_zoom_meetings_get_access_token’) ){
function woocommerce_to_zoom_meetings_get_access_token() {
$refresh_token = get_option(‘wc_settings_zoom_refresh_token’);
$url = ‘https://zoom.us/oauth/token’;
$response = wp_remote_post($url, array(
‘headers’ => array(
‘Content-Type’ => ‘application/x-www-form-urlencoded; charset=utf-8’,
‘Authorization’ => ‘Basic ‘.woocommerce_to_zoom_meetings_get_authorisation(),
‘Cache-Control’ => ‘no-cache’,
),
‘body’ => array(
‘refresh_token’ => $refresh_token,
‘grant_type’ => ‘refresh_token’,
),
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$refresh_token = $decodedBody[‘refresh_token’];
$access_token = $decodedBody[‘access_token’];
//update the options with the result
update_option(‘wc_settings_zoom_refresh_token’, $refresh_token);
return $access_token;
} else {
do_action( ‘zoom_meetings_authentication_failure’, $status, woocommerce_to_zoom_meetings_get_authorisation(), $refresh_token );
return ‘ERROR’;
}
}
}
?>
clear-transients.php
<?php
add_action( ‘wp_ajax_zoom_meetings_clear_transients’, ‘zoom_meetings_clear_transients’ );
function zoom_meetings_clear_transients(){
//clear the transients beginning with: zoom_meetings_registration_fields_
global $wpdb;
$sql = «DELETE FROM {$wpdb->options} WHERE option_name LIKE ‘_transient_zoom_meetings_registration_fields_%’ or option_name like ‘_transient_timeout_zoom_meetings_registration_fields_%'»;
$wpdb->query($sql);
echo ‘SUCCESS’;
wp_die();
}
?>
completed-order-email.php
<?php
add_action( ‘woocommerce_email_order_details’, ‘woocommerce_to_zoom_meetings_completed_order_email’, 20, 4 );
function woocommerce_to_zoom_meetings_completed_order_email( $order, $sent_to_admin = false, $plain_text = false, $email = » ) {
//only run if enabled in the plugin settings
$completed_order_email_enabled = get_option(‘wc_settings_zoom_meetings_enable_completed_order_email’);
if(isset($completed_order_email_enabled) && $completed_order_email_enabled == ‘yes’ && $email->id == ‘customer_completed_order’){
//start output
$html = »;
$order_id = $order->get_id();
if(get_post_meta($order_id,’zoom_meetings_registrant_ids’,false)){
$registrants = get_post_meta($order_id,’zoom_meetings_registrant_ids’,true);
$html .= ‘<h2>’.__(‘Meeting registrants’,’woocommerce-to-zoom-meetings’).'</h2>’;
//what we are going to do is some grouping here so we can display the meeting name
$data_by_meeting = array();
foreach($registrants as $key => $value){
$meeting_id = $value[‘meeting_id’];
if(!array_key_exists($meeting_id,$data_by_meeting)){
$data_by_meeting[$meeting_id] = array($value);
} else {
$existing_data = $data_by_meeting[$meeting_id];
array_push($existing_data,$value);
$data_by_meeting[$meeting_id] = $existing_data;
}
}
//get meeting data
$meeting_data = woocommerce_to_zoom_meetings_get_upcoming_meetings();
foreach($data_by_meeting as $meeting_id => $registrant_data){
//we need to get the meeting name
$html .= ‘<h4>’.apply_filters(‘woocommerce_to_zoom_meeting_title’,$meeting_data[$meeting_id]).'</h4>’;
$html .= ‘<ul style=»list-style: inherit; margin-bottom: 40px;»>’;
foreach($registrant_data as $value){
$html .= ‘<li data=»‘.$key.'»>’;
// $html .= ‘<a target=»_blank» href=»‘.$value[‘join_url’].'»><strong>’.$value[‘first_name’].’ ‘.$value[‘last_name’].'</strong> (‘.$value[‘email’].’)</a>’;
$html .= ‘<strong>’.$value[‘first_name’].’ ‘.$value[‘last_name’].'</strong> (‘.$value[‘email’].’) – <a target=»_blank» href=»‘.$value[‘join_url’].'»>’.__(‘Join link’,’woocommerce-to-zoom-meetings’).'</a>’;
$html .= ‘</li>’;
}
$html .= ‘</ul>’;
}
}
echo $html;
}
}
?>
meta-boxes.php
<?php
/**
*
*
*
* Add metabox to order page
*/
add_action( ‘add_meta_boxes’, ‘woocommerce_to_zoom_meetings_add_meta_boxes’ );
function woocommerce_to_zoom_meetings_add_meta_boxes(){
add_meta_box( ‘zoom_meeting_sync’, __(‘Zoom Meeting registrants’,’woocommerce-to-zoom-meetings’), ‘woocommerce_to_zoom_meetings_meta_box_order’, ‘shop_order’, ‘side’, ‘core’ );
add_meta_box( ‘zoom_meeting_registrant_data’, __(‘Zoom Meeting registrant Data’,’woocommerce-to-zoom-meetings’), ‘woocommerce_to_zoom_meetings_meta_box_order_registrant_data’, ‘shop_order’, ‘normal’, ‘core’ );
}
/**
*
*
*
* Add metabox content order
*/
function woocommerce_to_zoom_meetings_meta_box_order(){
global $post;
$order_id = $post->ID;
if(get_post_meta($order_id,’zoom_meetings_registrant_ids’,false)){
$registrants = get_post_meta($order_id,’zoom_meetings_registrant_ids’,true);
echo ‘<ul style=»list-style: inherit; margin-left: 20px;»>’;
foreach($registrants as $key => $value){
echo ‘<li data=»‘.$key.'»>’;
echo ‘<a target=»_blank» href=»‘.$value[‘join_url’].'»><strong>’.$value[‘first_name’].’ ‘.$value[‘last_name’].'</strong> (‘.$value[‘email’].’)</a>’;
echo ‘</li>’;
}
echo ‘</ul>’;
} else {
//show create registrants button
echo ‘<button id=»create-zoom-meetings-registrants» data=»‘.$order_id.'» class=»button button-primary»>’.__(‘Create registrants’,’woocommerce-to-zoom-meetings’).'</button>’;
}
}
/**
*
*
*
* Add metabox which displays registration data
*/
function woocommerce_to_zoom_meetings_meta_box_order_registrant_data(){
//start output
$html = »;
//do help message
$html .= ‘<em>’.__(‘Below lists the Zoom registration data submitted for this order. You can also update it if you wish and this can be handy if for example a user entered the wrong email address so they aren\’t technically registered in Zoom. Just note, if your order already has the completed status, you will need to change the status to pending (or something else) and then change it back to completed again, and this will trigger our plugin to sync to Zoom again with your updated data.’,’woocommerce-to-zoom-meetings’).'</em>’;
//get meeting data
$meeting_data = woocommerce_to_zoom_meetings_get_upcoming_meetings();
$html .= ‘<div id=»meeting-registration-data»>’;
global $post;
$order_id = $post->ID;
//get the metadata for the order
$all_post_meta = get_post_meta($order_id);
foreach($all_post_meta as $meta_key => $meta_value){
//only proceed for keys which contain zoom_meeting
if (strpos($meta_key, ‘zoom_meeting’) !== false) {
//key looks like: zoom_meeting-217072930-1
$key_exploded = explode(‘-‘,$meta_key);
if( array_key_exists(1,$key_exploded) ){
$meeting_id = $key_exploded[1];
$meta_value = get_post_meta($order_id,$meta_key,true);
if(array_key_exists($meeting_id,$meeting_data)){
$meeting_id = $meeting_data[$meeting_id];
}
$html .= ‘<div data=»‘.$meta_key.'» class=»regristrant-form»>’;
$html .= ‘<em>’.__(‘Meeting:’,’woocommerce-to-zoom-meetings’).’ ‘.$meeting_id.'</em>’;
if($meta_value){
foreach($meta_value as $key => $value){
$label = str_replace(‘_’,’ ‘,$key);
$label = ucwords($label);
if(!is_array($value)){
$html .= ‘<fieldset class=»registration-field»>’;
$html .= ‘<label for=»‘.$key.'»>’.$label.'</label>’;
$html .= ‘<input name=»‘.$key.'» id=»‘.$key.'» value=»‘.$value.'»>’;
$html .= ‘</fieldset>’;
}
}
}
$html .= ‘</div>’;
}
}
}
$html .= ‘</div>’;
//do save button
$html .= ‘<button data-order-id=»‘.$order_id.'» id=»save-zoom-meeting-registrant-data» class=»button button-primary»>’.__(‘Save Data’,’woocommerce-to-zoom-meetings’).'</button>’;
echo $html;
}
/**
*
*
*
* Updates the registration data
*/
add_action( ‘wp_ajax_zoom_meetings_save_registration_data’, ‘zoom_meetings_save_registration_data_callback’ );
function zoom_meetings_save_registration_data_callback(){
//clear the transients beginning with: zoom_registration_fields_
$order_id = intval($_POST[‘order_id’]);
$field_data = $_POST[‘field_data’];
if($field_data){
foreach($field_data as $key => $field_data_item){
$existing_data = get_post_meta($order_id, $key, true);
if($field_data_item){
foreach($field_data_item as $field_name => $field_value){
$existing_data[$field_name] = $field_value;
}
}
//update the post meta
update_post_meta($order_id, $key, $existing_data);
}
}
echo ‘SUCCESS’;
wp_die();
}
?>
my-account-order-view.php
<?php
/**
*
*
*
* Adds data to the order view on the my account page of woocommerce
*/
add_action( ‘woocommerce_view_order’, ‘woocommerce_to_zoom_meetings_my_account_view_order’, 20 );
function woocommerce_to_zoom_meetings_my_account_view_order($order_id){
//start output
$html = »;
if(get_post_meta($order_id,’zoom_meetings_registrant_ids’,false)){
$registrants = get_post_meta($order_id,’zoom_meetings_registrant_ids’,true);
$html .= ‘<h2>’.__(‘Meeting registrants’,’woocommerce-to-zoom-meetings’).'</h2>’;
//what we are going to do is some grouping here so we can display the meeting name
$data_by_meeting = array();
foreach($registrants as $key => $value){
$meeting_id = $value[‘meeting_id’];
if(!array_key_exists($meeting_id,$data_by_meeting)){
$data_by_meeting[$meeting_id] = array($value);
} else {
$existing_data = $data_by_meeting[$meeting_id];
array_push($existing_data,$value);
$data_by_meeting[$meeting_id] = $existing_data;
}
}
//get meeting data
$meeting_data = woocommerce_to_zoom_meetings_get_upcoming_meetings();
foreach($data_by_meeting as $meeting_id => $registrant_data){
//we need to get the meeting name
if( array_key_exists($meeting_id,$meeting_data) ){
$html .= ‘<h4>’.$meeting_data[$meeting_id].'</h4>’;
$html .= ‘<ul style=»list-style: inherit; margin-bottom: 40px;»>’;
foreach($registrant_data as $value){
$html .= ‘<li data=»‘.$key.'»>’;
// $html .= ‘<a target=»_blank» href=»‘.$value[‘join_url’].'»><strong>’.$value[‘first_name’].’ ‘.$value[‘last_name’].'</strong> (‘.$value[‘email’].’)</a>’;
$html .= ‘<strong>’.$value[‘first_name’].’ ‘.$value[‘last_name’].'</strong> (‘.$value[‘email’].’) – <a target=»_blank» href=»‘.$value[‘join_url’].'»>’.__(‘Join link’,’woocommerce-to-zoom-meetings’).'</a>’;
$html .= ‘</li>’;
}
$html .= ‘</ul>’;
}
}
}
echo $html;
}
?>
old-meeting-products.php
<?php
/**
*
*
*
* Automatically delete or make draft old meeting products
*/
add_action(‘admin_init’,’woocommerce_to_zoom_meetings_old_meeting_products’);
function woocommerce_to_zoom_meetings_old_meeting_products(){
//we want to only run this once per a day
$transient_name = ‘old_zoom_meeting_check’;
//check if transient doesn’t exist i.e. run
if(!get_transient($transient_name)){
//set the transient to prevent anything further happening
set_transient($transient_name, ‘RAN’, 1*DAY_IN_SECONDS);
//check the users setting
$setting = get_option(‘wc_settings_zoom_meetings_old_meeting_products’);
//only continue if we need to take an action
if(isset($setting) && $setting != ‘nothing’){
//get meetings
//only continue if authenticated
$meeting_data = array();
if(get_option(‘wc_settings_zoom_refresh_token’)){
$url = woocommerce_to_zoom_meetings_get_api_base().’users/me/meetings?page_size=300′;
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.woocommerce_to_zoom_meetings_get_access_token(),
)
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$meetings = $decodedBody[‘meetings’];
foreach($meetings as $meeting){
$meeting_start_timestamp = strtotime($meeting[‘start_time’]);
$meeting_id = $meeting[‘id’];
$meeting_data[$meeting_id] = $meeting_start_timestamp;
}
}
}
//only continue if we have data
if(count($meeting_data)>0){
//now we need to loop through the products and check if they have a meeting id
$args = array(
‘post_type’ => ‘product’,
‘posts_per_page’ => -1,
‘post_status’ => ‘publish’,
);
$products = get_posts( $args );
//only continue if products exist
if($products){
foreach($products as $product){
$product_id = $product->ID;
$meeting_id = get_post_meta( $product_id, ‘zoom_meeting_selection’, true );
$meeting_start_time = $meeting_data[$meeting_id];
//check to see if meeting id exists
if(strlen($meeting_id)>0 && strlen($meeting_start_time)>0){
//get the wordpress start time
$current_time = current_time( ‘timestamp’ );
//check time
if($current_time > $meeting_start_time){
//do actions
//do draft
if($setting == ‘draft’){
wp_update_post(array(
‘ID’ => $product_id,
‘post_status’ => ‘draft’
));
}
//do delete
if($setting == ‘delete’){
wp_trash_post( $product_id );
}
} //end check of time
} //end check if meeting id exists
} //end for each product
} //end check if products exist
} //end check of meeting data exists
} //end check if user setting is relevant
} //end transient check
}
?>
products-column.php
<?php
/**
*
*
*
* Add custom column to order page
*/
add_filter( ‘manage_edit-product_columns’, ‘woocommerce_to_zoom_meetings_add_column_to_product_page’ );
function woocommerce_to_zoom_meetings_add_column_to_product_page( $columns ){
$columns[‘zoom_meeting’] = __( ‘Zoom Meeting ID’, ‘woocommerce-to-zoom-meetings’ );
return $columns;
}
/**
*
*
*
* Add custom column to order page – content
*/
add_action( ‘manage_product_posts_custom_column’, ‘woocommerce_to_zoom_meetings_add_column_content_to_product_page’, 10, 2 );
function woocommerce_to_zoom_meetings_add_column_content_to_product_page( $column, $product_id ){
if ( $column == ‘zoom_meeting’ ) {
// $product = wc_get_product( $product_id );
$zoom_meeting_selection = get_post_meta($product_id,’zoom_meeting_selection’,true);
if(strlen($zoom_meeting_selection)>0){
echo ‘<a href=»https://zoom.us/meeting/’.$zoom_meeting_selection.'» target=»_blank»>’.$zoom_meeting_selection.'</a>’;
}
}
}
?>
settings.php
<?php
/**
*
*
*
* Add our new settings tab and settings
*/
class WC_Settings_WooCommerce_To_Zoom_Meetings {
/**
* Bootstraps the class and hooks required actions & filters.
*
*/
public static function init() {
add_filter( ‘woocommerce_settings_tabs_array’, __CLASS__ . ‘::add_settings_tab’, 50 );
add_action( ‘woocommerce_settings_tabs_zoommeetings’, __CLASS__ . ‘::settings_tab’ );
add_action( ‘woocommerce_update_options_zoommeetings’, __CLASS__ . ‘::update_settings’ );
}
/**
* Add a new settings tab to the WooCommerce settings tabs array.
*
* @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
* @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
*/
public static function add_settings_tab( $settings_tabs ) {
$settings_tabs[‘zoommeetings’] = __( ‘Zoom Meetings’, ‘woocommerce-to-zoom-meetings’ );
return $settings_tabs;
}
public static function output_right_sidebar_content( ) {
//frequently asked questions
$faq = array(
__(‘Users are not being registered for the Zoom meeting?’,’woocommerce-to-zoom-meetings’) => __(‘There are a couple of reasons this could occur:
<br></br>
<ol>
<li><strong>Orders aren\’t being marked as complete</strong> – Only completed orders are synced to Zoom. If you\’re using a payment method like PayPal or Stripe in test mode often they won\’t mark the orders as complete, however in live mode they do mark them as complete automatically. So for testing purposes just mark the order as complete from your <a href=»‘.get_admin_url().’edit.php?post_type=shop_order»>orders</a> page. If you are accepting cash or cheque payments or some kind of offline payment and you want to mark orders automatically as complete you can use this code snippet <a target=»_blank» href=»https://docs.woocommerce.com/document/automatically-complete-orders/»>here</a> or you can use this premium <a target=»_blank» href=»https://woocommerce.com/products/woocommerce-order-status-control/»>plugin</a> or use this free plugin <a href=»https://wordpress.org/plugins/autocomplete-woocommerce-orders/» target=»_blank»>here</a>.</li>
<li><strong>You are using an email on your Zoom account during your testing</strong> – If you are testing out the plugin you might have entered in your Zoom account email or the email of a user on your Zoom account during the checkout process. You can not register for your own meeting. So for testing purposes try a different email address and it should work ok.</li>
<li><strong>Ensure registration is required</strong> – In Zoom, on the meeting edit page, make sure for «registration» you have the «Required» checkbox checked.</li>
<li><strong>You have only authenticated users can join</strong> – In Zoom, on the meeting edit page, make sure for «Only authenticated users can join» is unchecked.</li>
<li><strong>You have set for the meeting that attendees must have a Zoom account</strong> – In Zoom, on the meeting edit page, turn off the the requirement that attendees must have a Zoom account.</li>
</ol><p>If you are certain that your meeting does not fall foul of the above criteria, please go to the WooCommerce logs page <a target=»_blank» href=»‘.get_admin_url().’admin.php?page=wc-status&tab=logs»>here</a> and in the dropdown in the top right hand corner, select an entry by our plugin which corresponds to the date of the order which did not sync to Zoom. You can then search for your order ID and see the corresponding error. If you need help translating what the error message means, please feel free to create a support request <a href=»https://northernbeacheswebsites.com.au/support» target=»_blank»>here</a>.</p>’,’woocommerce-to-zoom-meetings’),
__(‘How do I actually use this plugin?’,’woocommerce-to-zoom-meetings’) => __(‘Please follow the following steps:<br><ol>
<li>Enter the order/purchase email at the top of this settings page to receive automatic updates and support.</li>
<li>Click the big blue connect button on this page which will connect your website to your Zoom account. It\’s working when you see the status next to the button saying «Connected».</li>
<li>Create a WooCommerce product or go to an existing WooCommerce product and ensure you set the product as virtual and add any other parameters you want for the product like price etc. and then you will a meeting selection tab. This is where you can select your meeting. Once you are done click save settings.</li>
<li>That\’s it. Once someone purchases your product they will be automatically registered for the meeting.</li>
</ol>
‘,’woocommerce-to-zoom-meetings’),
__(‘When I click the «Connect with Zoom» button I get an error?’,’woocommerce-to-zoom’) => __(‘Make sure on this settings page you don\’t have «Sandbox Mode» activated. Please uncheck this, save the settings, refresh the page, and then click the connect button again. Otherwise, make sure you have a Zoom account to connect to.
‘,’woocommerce-to-zoom’),
__(‘I just added a new meeting in Zoom but can\’t see it on the product page?’,’woocommerce-to-zoom-meetings’) => __(‘Meetings are cached and get refreshed every hour so there may be some delay between updates in Zoom vs what is shown on your site. You can clear the cache though by clicking the link just above the save settings button on this settings page.’,’woocommerce-to-zoom-meetings’),
__(‘I can\’t see the Zoom meeting selection tab on the product page?’,’woocommerce-to-zoom-meetings’) => __(‘Please ensure you set the product as virtual – only once a product is set as virtual will the tab appear. Please check out this image <a target=»_blank» href=»https://northernbeacheswebsites.com.au/root-nbw/wp-content/uploads/2019/12/Zoom-Webinar-Product-Edit-Page-2048×586.jpg»>here</a> showing this. Also try re-connecting again by clicking the «Connect with Zoom» button on this page.’,’woocommerce-to-zoom-meetings’),
__(‘I don\’t want to select an existing meeting, I want to create a meeting in Zoom and add registrants to that new meeting using WooCommerce Bookings!’,’woocommerce-to-zoom-meetings’) => __(‘We currently support an integration with <a target=»_blank» href=»https://woocommerce.com/products/woocommerce-bookings/»>WooCommerce Bookings</a> so you can do just that. All you need to do is create your product and instead of selecting an existing meeting from the dropdown, just select the first item called «WooCommerce Bookings» and that\’s it!’,’woocommerce-to-zoom-meetings’),
__(‘How do users receive notification of successful registration?’,’woocommerce-to-zoom-meetings’) => __(‘This is all handled by Zoom and they provide a range of options to customise the emails. Please click <a target=»_blank» href=»https://support.zoom.us/hc/en-us/articles/203686335-Webinar-Email-Settings»>here</a> to learn more about this. There is also a setting on this page called «Enable Completed Order Email registration Links» which adds to the WooCommerce completed order email (so sent to the purchaser) which contains a list of registrants and their respective registration links.’,’woocommerce-to-zoom-meetings’),
__(‘I only want to see upcoming meetings in the dropdown on the product page?’,’woocommerce-to-zoom-meetings’) => __(‘You can use the following filter to only show upcoming meetings in the dropdown (note, this code should be placed in your themes functions.php file or a custom plugin):<br><code>add_filter( \’woocommerce_to_zoom_meetings_get_meetings_args\’, \’only_upcoming_meetings\’,10,1);<br>
function only_upcoming_meetings($args) {<br>
return $args.\’&type=upcoming\’;<br>
} </code>’,’woocommerce-to-zoom-meetings’),
__(‘I am having some kind of other issue?’,’woocommerce-to-zoom-meetings’) => __(‘First make sure you are using the latest version of this plugin; you can check for updates from your main <a href=»‘.get_admin_url().’plugins.php»>plugins page</a>. If this does not solve your issue please contact me <a target=»_blank» href=»https://northernbeacheswebsites.com.au/support/»>here</a>. Please note, I am located in Sydney, Australia so there may be some time difference in my reply however you will most certainly receive a response within 24 hours on weekdays.’,’woocommerce-to-zoom-meetings’),
__(‘Can I show meetings in a table and have registration forms on my site i.e. offer free meetings?’,’woocommerce-to-zoom-meetings’) => __(‘Yes! Follow these steps:
<ol>
<li>Create a page and put the following shortcode on it: [zoom_meetings_registration_table] (this is what shows the meetings in a table)</li>
<li>Now create another page and put the following shortcode on it: [zoom_meetings_registration_form] (this is where the registration forms will be)</li>
<li>On this plugin setting page select the page you just added the shortcode to in step 2 in the setting called «registration Page Selection»</li>
<li>Create a third thank you page which is where people will be redirected after completing the form and select this page in the settings on this page «Thank You Page Selection»</li>
<li>Now just direct visitors to the page you created in step 1!</li>
</ol>
‘,’woocommerce-to-zoom-meetings’),
);
//start output
$html = »;
$html .= ‘<div class=»faq-container-meetings»>’;
//do heading
$html .= ‘<ul class=»zoom-faq»>’;
$html .= ‘<h2>’.__(‘Frequently Asked Questions’,’woocommerce-to-zoom-meetings’).'</h2>’;
foreach($faq as $question => $answer){
$html .= ‘<li>’;
$html .= ‘<h2 class=»question»><span class=»dashicons dashicons-plus»></span> ‘.$question.'</h2>’;
$html .= ‘<span class=»answer»>’.$answer.'</span>’;
$html .= ‘</li>’;
}
$html .= ‘</ul>’;
$html .= ‘</div>’;
return $html;
}
public static function get_wordpress_pages() {
$options = array();
$pages = get_pages();
foreach($pages as $page){
$options[esc_html($page->ID)] = esc_html($page->post_title);
}
return $options;
}
/**
* Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function.
*
* @uses woocommerce_admin_fields()
* @uses self::get_settings()
*/
public static function settings_tab() {
woocommerce_admin_fields( self::get_settings() );
echo self::output_right_sidebar_content();
}
/**
* Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function.
*
* @uses woocommerce_update_options()
* @uses self::get_settings()
*/
public static function update_settings() {
woocommerce_update_options( self::get_settings() );
}
/**
* Get all the settings for this plugin for @see woocommerce_admin_fields() function.
*
* @return array Array of settings for @see woocommerce_admin_fields() function.
*/
public static function get_settings() {
$settings = array(
//updates
array(
‘name’ => __( ‘Licence Settings’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
),
array(
‘name’ => __( ‘Order Email’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘text’,
‘desc_tip’ => __( ‘The email used to purchase the plugin.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_order_email’
),
array(
‘name’ => __( ‘Order ID’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘text’,
‘desc_tip’ => __( ‘This order id number was sent to your email address upon purchase of the plugin. You should enter this like: 12345, not #12345 or any other variant.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_order_id’
),
array(
‘name’ => __( ‘Sandbox Mode’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘checkbox’,
‘desc_tip’ => __( ‘It is advised to keep this unchecked unless directed otherwise.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_sandbox_mode’
),
//section end
array( ‘type’ => ‘sectionend’ ),
array(
‘name’ => __( ‘Completed Order Notification’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
),
array(
‘name’ => __( ‘Enable Completed Order Email registration Links’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘checkbox’,
‘desc_tip’ => __( ‘When checked, we will add a list on your WooCommerce Completed Order email which will contain a list of meeting registrants and their respective registration links. Please ensure you have enabled your completed order email <a href=»‘.get_admin_url().’admin.php?page=wc-settings&tab=email»>here</a>.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_enable_completed_order_email’
),
//section end
array( ‘type’ => ‘sectionend’ ),
array(
‘name’ => __( ‘Additional registrant Notification’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
),
array(
‘name’ => __( ‘Enable Additional registrant Notification’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘checkbox’,
‘desc_tip’ => __( ‘By default Zoom should send registrants a confirmation email with the join link. However if Zoom is not doing this for some reason, or if you want to send an additional email, please check this setting. Like any email sent from WordPress it may not get delivered. We recommend using an SMTP plugin like this <a target=»_blank» href=»https://wordpress.org/plugins/wp-mail-smtp/»>one</a> to better guarantee delivery.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_enable_registrant_email’
),
array(
‘name’ => __( ‘Additional registrant Notification Email Subject’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘text’,
‘class’ => ‘hide-this-setting’,
‘desc_tip’ => __( ‘You may use the shortcodes: [registrant-first-name], [registrant-last-name], [registrant-email], [registrant-join-link], [meeting-passcode], [meeting-name], [meeting-date], [meeting-time] and [meeting-id] to create dynamic content for the subject.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_registrant_email_subject’
),
array(
‘name’ => __( ‘Additional registrant Notification Email Content’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘textarea’,
‘class’ => ‘hide-this-setting’,
‘desc_tip’ => __( ‘You may use the shortcodes: [registrant-first-name], [registrant-last-name], [registrant-email], [registrant-join-link], [meeting-passcode], [meeting-name], [meeting-date], [meeting-time] and [meeting-id] to create dynamic content for the subject. NOTE: line breaks created below will not be respected in the final email. If you want to do line breaks please use the HTML line break character i.e. < br >. So yes, HTML is supported below.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_registrant_email_content’
),
//section end
array( ‘type’ => ‘sectionend’ ),
array(
‘name’ => __( ‘Other Settings’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
),
array(
‘name’ => __( ‘What do you want to do with old meeting products in WooCommerce?’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘select’,
‘id’ => ‘wc_settings_zoom_meetings_old_meeting_products’,
‘options’ => array(‘nothing’=>__(‘Do nothing’,’woocommerce-to-zoom-meetings’),’draft’=>__(‘Make them a draft’,’woocommerce-to-zoom-meetings’),’delete’=>__(‘Delete them’,’woocommerce-to-zoom-meetings’))
),
array(
‘name’ => __( ‘Meetings to get’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘select’,
‘id’ => ‘wc_settings_zoom_meetings_to_get’,
‘options’ => array(‘mine’=>__(‘Only get my meetings’,’woocommerce-to-zoom-meetings’),’all’=>__(‘Get meetings from all users on my Zoom account’,’woocommerce-to-zoom-meetings’))
),
//section end
array( ‘type’ => ‘sectionend’ ),
array(
‘name’ => __( ‘Free Meeting Table & registration Forms’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
),
array(
‘name’ => __( ‘registration Page Selection’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘select’,
‘desc_tip’ => __( ‘Please first put the shortcode on any page of your choosing: [zoom_meetings_registration_table] then create a registration page and put the following shortcode on it: [zoom_meetings_registration_form] and then in this dropdown select the page which you put this registration form shortcode.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_registration_page’,
‘options’ => self::get_wordpress_pages()
),
array(
‘name’ => __( ‘Thank You Page Selection’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘select’,
‘desc_tip’ => __( ‘This is where you would like the registrant to go after the form has been successfully completed.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_thank_you_page’,
‘options’ => self::get_wordpress_pages()
),
//section end
array( ‘type’ => ‘sectionend’ ),
array(
‘name’ => __( ‘Checkout Page Options’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
),
array(
‘name’ => __( ‘Hide Checkout Form – read help before enabling’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘checkbox’,
‘desc_tip’ => __( ‘If this option is enabled we will hide the registration form on the checkout page. Caution, this should only be enabled if you are not adding custom/additional fields for the registration form in Zoom otherwise you will get registration errors. If you don\’t understand what this is all about, just leave this unchecked.’, ‘woocommerce-to-zoom-meetings’ ),
‘id’ => ‘wc_settings_zoom_meetings_hide_checkout_form’
),
//section end
array( ‘type’ => ‘sectionend’ ),
//connection
array(
‘name’ => __( ‘Connect with Zoom Meetings’, ‘woocommerce-to-zoom-meetings’ ),
‘type’ => ‘title’,
‘desc’ => woocommerce_to_zoom_meetings_connect_button(),
),
//section end
array( ‘type’ => ‘sectionend’ ),
);
return apply_filters( ‘wc_settings_zoom_meetings’, $settings );
}
}
WC_Settings_WooCommerce_To_Zoom_Meetings::init();
/**
*
*
*
* Output appropriate code for connect button and disconnect link
*/
function woocommerce_to_zoom_meetings_connect_button(){
//force check for updates of the plugin
woocommerce_to_zoom_meetings_force_check_for_updates();
//output connect button
$connectUrl = ‘https://zoom.us/oauth/authorize?response_type=code&’;
$connectUrl .= ‘client_id=’.woocommerce_to_zoom_meetings_get_client_id();
$connectUrl .= ‘&’;
$connectUrl .= ‘redirect_uri=’.woocommerce_to_zoom_meetings_get_redirect_uri();
$connectUrl .= ‘&’;
$connectUrl .= ‘state=’.get_admin_url().’zoommeeting’;
$return_data = ‘<a target=»_self» href=»‘.$connectUrl.'» id=»zoom-connect-button» class=»button-secondary»><span class=»video-icon dashicons dashicons-video-alt2″></span> ‘.__(‘Connect with Zoom’,’woocommerce-to-zoom-meetings’).'</a>’;
//lets also show a connected status
if(get_option(‘wc_settings_zoom_refresh_token’) && strlen(get_option(‘wc_settings_zoom_refresh_token’))>0){
$return_data .= ‘<span class=»connection-container»><span class=»status-text»>’.__(‘Status:’,’woocommerce-to-zoom-meetings’).'</span> <span class=»connected-text»>’.__(‘Connected’,’woocommerce-to-zoom-meetings’).'</span> <a class=»disconnect-from-zoom-meetings» href=»#»>’.__(‘Disconnect Now’,’woocommerce-to-zoom-meetings’).'</a></span>’;
} else {
$return_data .= ‘<span class=»connection-container»><span class=»status-text»>’.__(‘Status:’,’woocommerce-to-zoom-meetings’).'</span> <span class=»disconnected-text»>’.__(‘Disconnected’,’woocommerce-to-zoom-meetings’).'</span></span>’;
}
//lets also output the ability to clear transients
$return_data .= ‘<div class=»transient-settings»><a id=»clear-zoom-meetings-transients» href=»#»>’.__(‘Clear Cache’,’woocommerce-to-zoom-meetings’).'</a> <em>’.__(‘(If you update your registration form fields in Zoom, the form fields will be cached for an hour so they may not show straight away, so use this button to clear the cache)’,’woocommerce-to-zoom-meetings’).'</em></div>’;
// $return_data .= ‘<br></br>Sandbox mode: ‘.get_option(‘wc_settings_zoom_meetings_sandbox_mode’);
return $return_data;
}
?>
shortcode-registration-form.php
<?php
/**
*
*
*
* get meeting information
*/
function woocommerce_to_zoom_meetings_get_meeting_information($meeting_id) {
//we are just going to get the existing transient and find a match to reduce API calls
$meetings = woocommerce_to_zoom_meetings_get_upcoming_meetings_shortcode();
foreach($meetings as $meeting){
$meetings_id = $meeting[‘id’];
if($meetings_id == $meeting_id){
return $meeting;
}
}
}
/**
*
*
*
* function to render a registration form field
*/
function woocommerce_to_zoom_meetings_render_field_row($question,$type) {
//type can be standard or custom
//do standard variables
if($type == ‘standard’){
$field_type_helper = array(
// ‘last_name’ => ‘text’,
‘address’ => ‘text’,
‘city’ => ‘text’,
‘country’ => ‘country’,
‘zip’ => ‘text’,
‘state’ => ‘text’,
‘phone’ => ‘tel’,
‘industry’ => ‘text’,
‘org’ => ‘text’,
‘job_title’ => ‘text’,
‘purchasing_time_frame’ => ‘text’,
‘role_in_purchase_process’ => ‘text’,
‘no_of_employees’ => ‘number’,
‘comments’ => ‘text’,
);
$field_name = $question[‘field_name’];
$field_type = $field_type_helper[$field_name];
$field_class = ‘standard’;
}
if($type == ‘custom’){
$field_type_helper = array(
‘short’ => ‘text’,
‘multiple’ => ‘select’, //we really need to investigate a better answer but this will do for now
‘single_radio’ => ‘select’,
‘single_dropdown’ => ‘select’,
);
$field_name = $question[‘title’];
$field_type = $field_type_helper[$question[‘type’]];
$field_answers = $question[‘answers’];
$field_class = ‘custom’;
}
$required = $question[‘required’];
//make the name nicer
$field_nice_name = str_replace(‘_’,’ ‘,$field_name);
$field_nice_name = ucwords($field_nice_name);
//start output
$html = »;
//exclude last name
if($field_name != ‘last_name’){
$html .= ‘<tr class=»»>’;
$html .= ‘<td>’;
$html .= ‘<label for=»‘.$field_name.'»>’;
$html .= __($field_nice_name,’woocommerce-to-zoom-meetings’);
if($required){
$html .= ‘ <span class=»zoom-required»>*</span>’;
}
$html .= ‘</label>’;
$html .= ‘</td>’;
if($required){
$html .= ‘<td class=»zoom-required-field»>’;
} else {
$html .= ‘<td>’;
}
//need to cycle through types here
if($field_type == ‘text’){
$html .= ‘<input type=»email» class=»zoom-registration-field zoom-registration-field-‘.$field_class.'» name=»‘.$field_name.'» value=»»>’;
}
if($field_type == ‘number’){
$html .= ‘<input type=»number» class=»zoom-registration-field zoom-registration-field-‘.$field_class.'» name=»‘.$field_name.'» value=»»>’;
}
if($field_type == ‘tel’){
$html .= ‘<input type=»tel» class=»zoom-registration-field zoom-registration-field-‘.$field_class.'» name=»‘.$field_name.'» value=»»>’;
}
if($field_type == ‘select’){
$html .= ‘<select class=»zoom-registration-field zoom-registration-field-‘.$field_class.'» name=»‘.$field_name.'»>’;
foreach($field_answers as $answer){
$html .= ‘<option value=»‘.$answer.'»>’.$answer.'</option>’;
}
$html .= ‘</select>’;
}
if($field_type == ‘country’){
$countries = array(
«AF» => «Afghanistan»,
«AL» => «Albania»,
«DZ» => «Algeria»,
«AS» => «American Samoa»,
«AD» => «Andorra»,
«AO» => «Angola»,
«AI» => «Anguilla»,
«AQ» => «Antarctica»,
«AG» => «Antigua and Barbuda»,
«AR» => «Argentina»,
«AM» => «Armenia»,
«AW» => «Aruba»,
«AU» => «Australia»,
«AT» => «Austria»,
«AZ» => «Azerbaijan»,
«BS» => «Bahamas»,
«BH» => «Bahrain»,
«BD» => «Bangladesh»,
«BB» => «Barbados»,
«BY» => «Belarus»,
«BE» => «Belgium»,
«BZ» => «Belize»,
«BJ» => «Benin»,
«BM» => «Bermuda»,
«BT» => «Bhutan»,
«BO» => «Bolivia»,
«BA» => «Bosnia and Herzegovina»,
«BW» => «Botswana»,
«BV» => «Bouvet Island»,
«BR» => «Brazil»,
«IO» => «British Indian Ocean Territory»,
«BN» => «Brunei Darussalam»,
«BG» => «Bulgaria»,
«BF» => «Burkina Faso»,
«BI» => «Burundi»,
«KH» => «Cambodia»,
«CM» => «Cameroon»,
«CA» => «Canada»,
«CV» => «Cape Verde»,
«KY» => «Cayman Islands»,
«CF» => «Central African Republic»,
«TD» => «Chad»,
«CL» => «Chile»,
«CN» => «China»,
«CX» => «Christmas Island»,
«CC» => «Cocos (Keeling) Islands»,
«CO» => «Colombia»,
«KM» => «Comoros»,
«CG» => «Congo»,
«CD» => «Congo, the Democratic Republic of the»,
«CK» => «Cook Islands»,
«CR» => «Costa Rica»,
«CI» => «Cote D’Ivoire»,
«HR» => «Croatia»,
«CU» => «Cuba»,
«CY» => «Cyprus»,
«CZ» => «Czech Republic»,
«DK» => «Denmark»,
«DJ» => «Djibouti»,
«DM» => «Dominica»,
«DO» => «Dominican Republic»,
«EC» => «Ecuador»,
«EG» => «Egypt»,
«SV» => «El Salvador»,
«GQ» => «Equatorial Guinea»,
«ER» => «Eritrea»,
«EE» => «Estonia»,
«ET» => «Ethiopia»,
«FK» => «Falkland Islands (Malvinas)»,
«FO» => «Faroe Islands»,
«FJ» => «Fiji»,
«FI» => «Finland»,
«FR» => «France»,
«GF» => «French Guiana»,
«PF» => «French Polynesia»,
«TF» => «French Southern Territories»,
«GA» => «Gabon»,
«GM» => «Gambia»,
«GE» => «Georgia»,
«DE» => «Germany»,
«GH» => «Ghana»,
«GI» => «Gibraltar»,
«GR» => «Greece»,
«GL» => «Greenland»,
«GD» => «Grenada»,
«GP» => «Guadeloupe»,
«GU» => «Guam»,
«GT» => «Guatemala»,
«GN» => «Guinea»,
«GW» => «Guinea-Bissau»,
«GY» => «Guyana»,
«HT» => «Haiti»,
«HM» => «Heard Island and Mcdonald Islands»,
«VA» => «Holy See (Vatican City State)»,
«HN» => «Honduras»,
«HK» => «Hong Kong»,
«HU» => «Hungary»,
«IS» => «Iceland»,
«IN» => «India»,
«ID» => «Indonesia»,
«IR» => «Iran, Islamic Republic of»,
«IQ» => «Iraq»,
«IE» => «Ireland»,
«IL» => «Israel»,
«IT» => «Italy»,
«JM» => «Jamaica»,
«JP» => «Japan»,
«JO» => «Jordan»,
«KZ» => «Kazakhstan»,
«KE» => «Kenya»,
«KI» => «Kiribati»,
«KP» => «Korea, Democratic People’s Republic of»,
«KR» => «Korea, Republic of»,
«KW» => «Kuwait»,
«KG» => «Kyrgyzstan»,
«LA» => «Lao People’s Democratic Republic»,
«LV» => «Latvia»,
«LB» => «Lebanon»,
«LS» => «Lesotho»,
«LR» => «Liberia»,
«LY» => «Libyan Arab Jamahiriya»,
«LI» => «Liechtenstein»,
«LT» => «Lithuania»,
«LU» => «Luxembourg»,
«MO» => «Macao»,
«MK» => «Macedonia, the Former Yugoslav Republic of»,
«MG» => «Madagascar»,
«MW» => «Malawi»,
«MY» => «Malaysia»,
«MV» => «Maldives»,
«ML» => «Mali»,
«MT» => «Malta»,
«MH» => «Marshall Islands»,
«MQ» => «Martinique»,
«MR» => «Mauritania»,
«MU» => «Mauritius»,
«YT» => «Mayotte»,
«MX» => «Mexico»,
«FM» => «Micronesia, Federated States of»,
«MD» => «Moldova, Republic of»,
«MC» => «Monaco»,
«MN» => «Mongolia»,
«MS» => «Montserrat»,
«MA» => «Morocco»,
«MZ» => «Mozambique»,
«MM» => «Myanmar»,
«NA» => «Namibia»,
«NR» => «Nauru»,
«NP» => «Nepal»,
«NL» => «Netherlands»,
«AN» => «Netherlands Antilles»,
«NC» => «New Caledonia»,
«NZ» => «New Zealand»,
«NI» => «Nicaragua»,
«NE» => «Niger»,
«NG» => «Nigeria»,
«NU» => «Niue»,
«NF» => «Norfolk Island»,
«MP» => «Northern Mariana Islands»,
«NO» => «Norway»,
«OM» => «Oman»,
«PK» => «Pakistan»,
«PW» => «Palau»,
«PS» => «Palestinian Territory, Occupied»,
«PA» => «Panama»,
«PG» => «Papua New Guinea»,
«PY» => «Paraguay»,
«PE» => «Peru»,
«PH» => «Philippines»,
«PN» => «Pitcairn»,
«PL» => «Poland»,
«PT» => «Portugal»,
«PR» => «Puerto Rico»,
«QA» => «Qatar»,
«RE» => «Reunion»,
«RO» => «Romania»,
«RU» => «Russian Federation»,
«RW» => «Rwanda»,
«SH» => «Saint Helena»,
«KN» => «Saint Kitts and Nevis»,
«LC» => «Saint Lucia»,
«PM» => «Saint Pierre and Miquelon»,
«VC» => «Saint Vincent and the Grenadines»,
«WS» => «Samoa»,
«SM» => «San Marino»,
«ST» => «Sao Tome and Principe»,
«SA» => «Saudi Arabia»,
«SN» => «Senegal»,
«CS» => «Serbia and Montenegro»,
«SC» => «Seychelles»,
«SL» => «Sierra Leone»,
«SG» => «Singapore»,
«SK» => «Slovakia»,
«SI» => «Slovenia»,
«SB» => «Solomon Islands»,
«SO» => «Somalia»,
«ZA» => «South Africa»,
«GS» => «South Georgia and the South Sandwich Islands»,
«ES» => «Spain»,
«LK» => «Sri Lanka»,
«SD» => «Sudan»,
«SR» => «Suriname»,
«SJ» => «Svalbard and Jan Mayen»,
«SZ» => «Swaziland»,
«SE» => «Sweden»,
«CH» => «Switzerland»,
«SY» => «Syrian Arab Republic»,
«TW» => «Taiwan, Province of China»,
«TJ» => «Tajikistan»,
«TZ» => «Tanzania, United Republic of»,
«TH» => «Thailand»,
«TL» => «Timor-Leste»,
«TG» => «Togo»,
«TK» => «Tokelau»,
«TO» => «Tonga»,
«TT» => «Trinidad and Tobago»,
«TN» => «Tunisia»,
«TR» => «Turkey»,
«TM» => «Turkmenistan»,
«TC» => «Turks and Caicos Islands»,
«TV» => «Tuvalu»,
«UG» => «Uganda»,
«UA» => «Ukraine»,
«AE» => «United Arab Emirates»,
«GB» => «United Kingdom»,
«US» => «United States»,
«UM» => «United States Minor Outlying Islands»,
«UY» => «Uruguay»,
«UZ» => «Uzbekistan»,
«VU» => «Vanuatu»,
«VE» => «Venezuela»,
«VN» => «Viet Nam»,
«VG» => «Virgin Islands, British»,
«VI» => «Virgin Islands, U.s.»,
«WF» => «Wallis and Futuna»,
«EH» => «Western Sahara»,
«YE» => «Yemen»,
«ZM» => «Zambia»,
«ZW» => «Zimbabwe»
);
$html .= ‘<select class=»zoom-registration-field zoom-registration-field-‘.$field_class.'» name=»‘.$field_name.'»>’;
foreach($countries as $country_id => $country_name){
$html .= ‘<option value=»‘.$country_id.'»>’.$country_name.'</option>’;
}
$html .= ‘</select>’;
}
$html .= ‘</td>’;
$html .= ‘</tr>’;
}
return $html;
}
/**
*
*
*
* shortcode for displaying the registration form table
*/
add_shortcode(‘zoom_meetings_registration_form’, ‘woocommerce_to_zoom_meetings_registration_form’);
function woocommerce_to_zoom_meetings_registration_form($atts){
//do attributes – currently none – in the future we will look at this
$attribute = shortcode_atts( array(
» => »,
), $atts );
//output styles and scripts
wp_enqueue_style(array(‘woocommerce-to-zoom-meetings-shortcode-style’));
wp_enqueue_script(array(‘woocommerce-to-zoom-meetings-shortcode-script’,’woocommerce-to-zoom-meetings-fontawesome’));
$html = »;
//get query string of meeting
$meeting_id = $_GET[‘meeting_id’];
if(strlen($meeting_id)>0){
$meeting = woocommerce_to_zoom_meetings_get_meeting_information($meeting_id);
$meeting_topic = $meeting[‘topic’];
$meeting_type = $meeting[‘type’]; //5 = meeting,6 = recurrence meeting,9=recurring meeting with fixed time
$meeting_duration = $meeting[‘duration’]; //180 in minutes
$meeting_timezone = $meeting[‘timezone’]; //America/Los_Angeles
$meeting_start = new DateTime($meeting[‘start_time’], new DateTimeZone(‘UTC’));
$meeting_start->setTimezone(new DateTimeZone($meeting_timezone));
$meeting_agenda = $meeting[‘agenda’]; //description
//if the agenda is greater than 250, let’s say 245 characters, lets do an additional call to the meeting to get the full agenda
if( strlen($meeting_agenda) > 245 ){
//get more info on meeting
$meeting_agenda = woocommerce_to_zoom_meetings_get_meeting_information_extended($meeting_id);
}
//do duration work
if(intval($meeting_duration)>60){
$hours = intval($meeting_duration)/60;
$meeting_duration = $hours.’ ‘.__(‘hours’,’woocommerce-to-zoom-meetings’);
} else {
$meeting_duration = $meeting_duration.’ ‘.__(‘minutes’,’woocommerce-to-zoom-meetings’);
}
//do start
$meeting_start_combined = $meeting_start->format(get_option(‘date_format’).’ ‘.get_option(‘time_format’).’ T’);
//do header
$html .= ‘<div class=»zoom-meeting-information»>’;
//do heading
$html .= ‘<h2>’.$meeting_topic.'</h2>’;
//do meta
$html .= ‘<ul class=»meeting-meta»>’;
$html .= ‘<li class=»meeting-start»><i class=»far fa-clock»></i> ‘.$meeting_start_combined.'</li>’;
$html .= ‘<li class=»meeting-duration»><i class=»fas fa-hourglass-half»></i> ‘.$meeting_duration.'</li>’;
$html .= ‘</ul>’;
//do description
if(strlen($meeting_agenda)>0){
$html .= ‘<span class=»meeting-agenda-registration-page»>’.$meeting_agenda.'</span>’;
}
$html .= ‘</div>’;
//do form
$html .= ‘<table id=»zoom-meeting-form» class=»zoom-meeting-form»>’;
//get registration fields
$registration_fields = woocommerce_to_zoom_meetings_get_meeting_registration_fields($meeting_id);
// var_dump($registration_fields);
//do compulsory fields
$html .= ‘<tr>’;
$html .= ‘<td><label for=»first_name»>’.__(‘First name’,’woocommerce-to-zoom-meetings’).’ <span class=»zoom-required»>*</span></label></td>’;
$html .= ‘<td class=»zoom-required-field»><input type=»text» class=»zoom-registration-field zoom-registration-field-standard» name=»first_name» value=»»></td>’;
$html .= ‘</tr>’;
$html .= ‘<tr>’;
$html .= ‘<td><label for=»last_name»>’.__(‘Last name’,’woocommerce-to-zoom-meetings’).’ <span class=»zoom-required»>*</span></label></td>’;
$html .= ‘<td class=»zoom-required-field»><input type=»text» class=»zoom-registration-field zoom-registration-field-standard» name=»last_name» value=»»></td>’;
$html .= ‘</tr>’;
$html .= ‘<tr>’;
$html .= ‘<td><label for=»email»>’.__(‘Email’,’woocommerce-to-zoom-meetings’).’ <span class=»zoom-required»>*</span></label></td>’;
$html .= ‘<td class=»zoom-required-field»><input type=»email» class=»zoom-registration-field zoom-registration-field-standard» name=»email» value=»»></td>’;
$html .= ‘</tr>’;
//do standard fields
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0){
foreach($registration_fields[‘questions’] as $question){
$html .= woocommerce_to_zoom_meetings_render_field_row($question,’standard’);
}
}
//do custom fields
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0){
foreach($registration_fields[‘custom_questions’] as $question){
$html .= woocommerce_to_zoom_meetings_render_field_row($question,’custom’);
}
}
//do submit
$html .= ‘<tr>’;
$html .= ‘<td></td>’;
$html .= ‘<td><button data-waiting=»‘.__(‘Please wait…’,’woocommerce-to-zoom-meetings’).'» data-meeting-id=»‘.$meeting_id.'» class=»zoom-registration-form-submit»>’.__(‘Submit’,’woocommerce-to-zoom-meetings’).'</button></td>’;
$html .= ‘</tr>’;
$html .= ‘</table>’;
} else {
$html .= __(‘This page should only be accessed by clicking the registration link in the meeting table.’,’woocommerce-to-zoom-meetings’);
}
return $html;
}
?>
shortcode-registration-table.php
<?php
/**
*
*
*
* shortcode for displaying the registration form table
*/
add_shortcode(‘zoom_meetings_registration_table’, ‘woocommerce_to_zoom_meetings_registration_table’);
function woocommerce_to_zoom_meetings_registration_table($atts){
//do attributes – currently none – in the future we will look at this
$attribute = shortcode_atts( array(
» => »,
), $atts );
//output styles and scripts
wp_enqueue_style(array(‘woocommerce-to-zoom-meetings-shortcode-style’));
wp_enqueue_script(array(‘woocommerce-to-zoom-meetings-shortcode-script’,’woocommerce-to-zoom-meetings-fontawesome’));
//lets get the upcoming meetings
$meetings = woocommerce_to_zoom_meetings_get_upcoming_meetings_shortcode();
//process the meetings so we don’t show get ones in the past and put them in order
$meetings_sorted = array();
$meetings_data = array();
foreach($meetings as $meeting){
$timezone = new DateTimeZone($meeting[‘timezone’]);
$offset = $timezone->getOffset(new DateTime);
$meeting_start = date(‘U’,strtotime($meeting[‘start_time’]))+$offset;
$meeting_id = $meeting[‘id’];
$current_time = current_time( ‘timestamp’ );
if($meeting_start > $current_time){
$meetings_sorted[$meeting_id] = $meeting_start;
$meetings_data[$meeting_id] = $meeting;
}
}
//sort the array
asort($meetings_sorted);
$good_meeting_list = array();
foreach($meetings_sorted as $meeting_id => $meeting_start){
array_push($good_meeting_list,$meetings_data[$meeting_id]);
}
$good_meeting_list = apply_filters( ‘woocommerce_to_zoom_meetings_modify_meetings_for_table’, $good_meeting_list );
//registration page
$registration_page = get_option(‘wc_settings_zoom_meetings_registration_page’);
if(strlen($registration_page)>0){
$registration_page_link = get_permalink( $registration_page );
} else {
$registration_page_link = ‘#’;
}
// var_dump($meetings);
//start output
$html = »;
//start table
$html .= ‘<table class=»zoom-meeting-table»>’;
//do table header
$html .= ‘<thead>’;
$html .= ‘<tr>’;
$html .= ‘<th>’.__(‘Topic’,’woocommerce-to-zoom-meetings’).'</th>’;
// $html .= ‘<th>’.__(‘Date’,’woocommerce-to-zoom-meetings’).'</th>’;
$html .= ‘<th>’.__(‘Start Time’,’woocommerce-to-zoom-meetings’).'</th>’;
$html .= ‘<th>’.__(‘Duration’,’woocommerce-to-zoom-meetings’).'</th>’;
$html .= ‘<th>’.__(‘Register’,’woocommerce-to-zoom-meetings’).'</th>’;
$html .= ‘</tr>’;
$html .= ‘</thead>’;
//do table body
$html .= ‘<tbody>’;
if(count($good_meeting_list)>0){
//now loop through the meetings
foreach($good_meeting_list as $meeting){
$meeting_id = $meeting[‘id’]; //687492379
$meeting_topic = $meeting[‘topic’]; //aka title
$meeting_type = $meeting[‘type’]; //5 = meeting,6 = recurrence meeting,9=recurring meeting with fixed time
$meeting_duration = $meeting[‘duration’]; //180 in minutes
$meeting_timezone = $meeting[‘timezone’]; //America/Los_Angeles
$meeting_start = new DateTime($meeting[‘start_time’], new DateTimeZone(‘UTC’));
$meeting_start->setTimezone(new DateTimeZone($meeting_timezone));
$meeting_agenda = $meeting[‘agenda’]; //description
//do duration work
if(intval($meeting_duration)>60){
$hours = intval($meeting_duration)/60;
$meeting_duration = $hours.’ ‘.__(‘hours’,’woocommerce-to-zoom-meetings’);
} else {
$meeting_duration = $meeting_duration.’ ‘.__(‘minutes’,’woocommerce-to-zoom-meetings’);
}
//do start
$meeting_start_combined = $meeting_start->format(get_option(‘date_format’).’ ‘.get_option(‘time_format’).’ T’);
//do description
if(strlen($meeting_agenda)>0){
$meeting_topic = $meeting_topic.’ <i class=»meeting-agenda-icon fas fa-info-circle»></i><span class=»meeting-agenda»>’.$meeting_agenda.'</span>’;
}
//do registration link
if($registration_page_link != ‘#’){
$registration_page_link_modified = $registration_page_link.’?meeting_id=’.$meeting_id;
} else {
$registration_page_link_modified = $registration_page_link;
}
$html .= ‘<tr>’;
$html .= ‘<td>’.$meeting_topic.'</td>’;
$html .= ‘<td>’.$meeting_start_combined.'</td>’;
// $html .= ‘<td>’.$meeting_start_time.'</td>’;
$html .= ‘<td>’.$meeting_duration.'</td>’;
$html .= ‘<td><a href=»‘.$registration_page_link_modified.'»>’.__(‘Register’,’woocommerce-to-zoom-meetings’).’ <i class=»fas fa-arrow-circle-right»></i></a></td>’;
$html .= ‘</tr>’;
}
} else {
$html .= ‘<tr><td colspan=»5″>’.__(‘There are currently no upcoming meetings.’,’woocommerce-to-zoom-meetings’).'</td></tr>’;
}
$html .= ‘</tbody>’;
$html .= ‘</table>’;
return $html;
}
/**
*
*
*
* Gets upcoming meetings from Zoom
*/
function woocommerce_to_zoom_meetings_get_upcoming_meetings_shortcode() {
$transient_name = ‘zoom_upcoming_meetings_shortcode’;
$transient = get_transient($transient_name);
if ($transient != false){
return $transient;
} else {
//only continue if authenticated
if(get_option(‘wc_settings_zoom_refresh_token’)){
$url = woocommerce_to_zoom_meetings_get_api_base().’users/me/meetings?’.apply_filters( ‘woocommerce_to_zoom_meetings_get_meetings_all_args’, ‘page_size=300’ );
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.woocommerce_to_zoom_meetings_get_access_token(),
)
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$meetings = $decodedBody[‘meetings’];
//set the transient for 10 minutes
set_transient($transient_name,$meetings, MINUTE_IN_SECONDS * 60);
}
}
return $meetings;
}
}
/**
*
*
*
* Gets information for a specific meeting – we do this as the list of meetings doesnt bring back the full agenda
*/
function woocommerce_to_zoom_meetings_get_meeting_information_extended($meeting_id) {
$transient_name = ‘zoom_meeting_’.$meeting_id;
$transient = get_transient($transient_name);
if ($transient != false){
return $transient;
} else {
//only continue if authenticated
if(get_option(‘wc_settings_zoom_refresh_token’)){
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$meeting_id;
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.woocommerce_to_zoom_meetings_get_access_token(),
)
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
$full_agenda = $decodedBody[‘agenda’];
//set the transient for 10 minutes
set_transient($transient_name, $full_agenda, DAY_IN_SECONDS * 1);
}
}
return $full_agenda;
}
}
?>
woocommerce-checkout-form.php
<?php
/**
*
*
*
* Gets registration fields for a meeting
*/
function woocommerce_to_zoom_meetings_get_meeting_registration_fields($meeting_id) {
$meeting_id = woocommerce_to_zoom_meetings_sanitize_meeting_id($meeting_id);
$transient_name = ‘zoom_meetings_registration_fields_’.$meeting_id;
$transient = get_transient($transient_name);
if ($transient != false){
return $transient;
} else {
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$meeting_id.’/registrants/questions’;
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.woocommerce_to_zoom_meetings_get_access_token(),
)
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
//set the transient for 1 hour
set_transient($transient_name,$decodedBody, 60*60);
return $decodedBody;
}
}
}
/**
*
*
*
* Gets registration fields for a meeting
*/
function woocommerce_to_zoom_meetings_get_recording_registration_fields($recording_id) {
$recording_id = woocommerce_to_zoom_meetings_sanitize_meeting_id($recording_id);
$transient_name = ‘zoom_meetings_registration_fields_’.$recording_id;
$transient = get_transient($transient_name);
if ($transient != false){
return $transient;
} else {
$url = woocommerce_to_zoom_meetings_get_api_base().’meetings/’.$recording_id.’/registrants/questions’;
$response = wp_remote_get( $url, array(
‘headers’ => array(
‘Authorization’ => ‘Bearer ‘.woocommerce_to_zoom_meetings_get_access_token(),
)
));
$status = wp_remote_retrieve_response_code( $response );
if($status == 200){
$decodedBody = json_decode(preg_replace(‘/(«\w+»):(\d+(\.\d+)?)/’, ‘\\1:»\\2″‘, $response[‘body’]), true);
//set the transient for 1 hour
set_transient($transient_name,$decodedBody, 60*60);
return $decodedBody;
}
}
}
/**
*
*
*
* Adds custom fields to the woocommerce checkout area
*/
add_action( ‘woocommerce_after_order_notes’, ‘woocommerce_to_zoom_meetings_checkout_fields’ );
function woocommerce_to_zoom_meetings_checkout_fields( $checkout ) {
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
//do pre-query to find out whether meetings exist for the purpose of the button
$meetings_exist = false;
foreach ( $cart as $item_key => $item_value ) {
$cart_product_id = $item_value[ ‘data’ ] -> get_id();
$meeting_id = get_post_meta( $cart_product_id, ‘zoom_meeting_selection’, true );
if(strlen($meeting_id)>0){
$meetings_exist = true;
}
}
//add class to specific areas to hide it
$hide_checkout_form = get_option(‘wc_settings_zoom_meetings_hide_checkout_form’);
if($hide_checkout_form == ‘yes’){
$additional_class = ‘zoom-meetings-hide-checkout-form’;
} else {
$additional_class = »;
}
//do button if meetings exist
if($meetings_exist){
echo ‘<button class=»woocommerce-to-zoom-meetings-copy-from-billing ‘.$additional_class.'»>’.__(‘Copy from billing details’,’woocommerce-to-zoom-meetings’).'</button>’;
}
//we need to capture unique data
$meeting_combos_used = array();
//loop through each item in the cart
foreach ( $cart as $item_key => $item_value ) {
//get variables for the cart item
$cart_product_id = $item_value[ ‘data’ ] -> get_id();
$cart_product_title = $item_value[ ‘data’ ] -> get_name();
$cart_product_slug = $item_value[ ‘data’ ]->get_slug();
$cart_product_qty = $item_value[‘quantity’];
$meeting_data = woocommerce_to_zoom_meetings_get_upcoming_meetings();
//if it is a booking instead of using the quantity use the persons instead
if(array_key_exists(‘booking’,$item_value)){
$number_of_persons = $item_value[‘booking’][‘Persons’];;
//we need to make sure there’s at least 1 registrant!
if($number_of_persons == 0){
$number_of_persons = 1;
}
$cart_product_qty = $number_of_persons;
}
$meeting_id = get_post_meta( $cart_product_id, ‘zoom_meeting_selection’, true );
// $meeting_id = woocommerce_to_zoom_meetings_sanitize_meeting_id($meeting_id);
if(strlen($meeting_id)>0){
$multiple_meetings = explode(‘,’,$meeting_id);
foreach($multiple_meetings as $meeting_id){
// var_dump($meeting_id);
echo ‘<div class=»zoom-meeting-section» style=»margin-top: 30px;»>’;
do_action( ‘woocommerce_to_zoom_meetings_before_product_title’,$item_value );
//do heading
// echo ‘<h3 class=»‘.$additional_class.'»>’.$cart_product_title.'</h3>’;
echo ‘<h3 class=»‘.$additional_class.'»>’.apply_filters(‘woocommerce_to_zoom_meeting_title’,$meeting_data[$meeting_id]).'</h3>’;
do_action( ‘woocommerce_to_zoom_meetings_after_product_title’,$item_value );
//lets get the registration fields for the meeting
$registration_fields = woocommerce_to_zoom_meetings_get_meeting_registration_fields($meeting_id);
// var_dump($registration_fields);
//lets now loop through each registrant by using the QTY as a guide
for ($i = 1 ; $i <= $cart_product_qty; $i++){
if(!array_key_exists($meeting_id,$meeting_combos_used)){
$meeting_combos_used[$meeting_id] = 0;
}
$meeting_combos_used[$meeting_id] = $meeting_combos_used[$meeting_id]+1;
$number_to_use = $meeting_combos_used[$meeting_id];
echo ‘<div class=»zoom-meeting-registrant-container ‘.$additional_class.’-‘.$number_to_use.'»>’;
echo ‘<strong class=»zoom-meeting-registrant-section»>’.__(‘registrant’,’woocommerce-to-zoom-meetings’).’ ‘.$number_to_use.'</strong>’;
//first we need to do the required fields which is the first name and email
//DO FIRST NAME
$field_identifier = $meeting_id.’-‘.$number_to_use.’-first_name’;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-first_name first_name’);
$name_email_required = apply_filters(‘woocommerce_to_zoom_meetings_fields_required’, true, $meeting_id, $number_to_use );
$field_options = array();
woocommerce_form_field( $field_identifier, array(
‘type’ => ‘text’,
‘required’ => $name_email_required,
‘class’ => $field_class,
‘label’ => __(‘First Name’,’woocommerce-to-zoom-meetings’),
‘maxlength’ => false,
‘placeholder’ => apply_filters( ‘woocommerce_to_zoom_meetings_placeholder_first_name’, » ),
‘options’ => $field_options,
), $checkout->get_value( $field_identifier ));
//DO LAST NAME
$field_identifier = $meeting_id.’-‘.$number_to_use.’-last_name’;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-last_name last_name’);
$field_options = array();
woocommerce_form_field( $field_identifier, array(
‘type’ => ‘text’,
‘required’ => $name_email_required,
‘class’ => $field_class,
‘label’ => __(‘Last Name’,’woocommerce-to-zoom-meetings’),
‘maxlength’ => false,
‘placeholder’ => apply_filters( ‘woocommerce_to_zoom_meetings_placeholder_last_name’, » ),
‘options’ => $field_options,
), $checkout->get_value( $field_identifier ));
//DO EMAIL
$field_identifier = $meeting_id.’-‘.$number_to_use.’-email’;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-email email’);
$field_options = array();
woocommerce_form_field( $field_identifier, array(
‘type’ => ‘text’,
‘required’ => $name_email_required,
‘class’ => $field_class,
‘label’ => __(‘Email’,’woocommerce-to-zoom-meetings’),
‘maxlength’ => false,
‘placeholder’ => apply_filters( ‘woocommerce_to_zoom_meetings_placeholder_email’, » ),
‘options’ => $field_options,
), $checkout->get_value( $field_identifier ));
//now we need to do our API registration fields
//lets do our standard fields first
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0 && strpos($meeting_id, ‘WooCommerceBookings’) === false){
$field_type_helper = array(
// ‘last_name’ => ‘text’,
‘address’ => ‘text’,
‘city’ => ‘text’,
‘country’ => ‘country’,
‘zip’ => ‘text’,
‘state’ => ‘state’,
‘phone’ => ‘tel’,
‘industry’ => ‘text’,
‘org’ => ‘text’,
‘job_title’ => ‘text’,
‘purchasing_time_frame’ => ‘text’,
‘role_in_purchase_process’ => ‘text’,
‘no_of_employees’ => ‘number’,
‘comments’ => ‘text’,
);
foreach($registration_fields[‘questions’] as $question){
$field_name = $question[‘field_name’];
//dont do last name field because we have already done it
if($field_name != ‘last_name’){
$required = $question[‘required’];
$field_identifier = $meeting_id.’-‘.$number_to_use.’-‘.$field_name;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-‘.$field_name.’ ‘.$field_name);
$label = str_replace(‘_’,’ ‘,$field_name);
$label = ucwords($label);
woocommerce_form_field( $field_identifier, array(
‘type’ => $field_type_helper[$field_name],
‘required’ => $required,
‘class’ => $field_class,
‘label’ => __($label,’woocommerce-to-zoom-meetings’),
), $checkout->get_value( $field_identifier ));
}
}
}
//now lets do our custom questions
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0 && strpos($meeting_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘custom_questions’] as $question){
$field_title = $question[‘title’];
$field_title_translated = base64_encode($field_title);
$field_title_for_class = strip_tags($field_title);
$field_title_for_class = strtolower($field_title_for_class);
$field_title_for_class = str_replace(‘ ‘,’-‘,$field_title_for_class);
$field_title_for_class = str_replace(‘(‘,»,$field_title_for_class);
$field_title_for_class = str_replace(‘)’,»,$field_title_for_class);
$required = $question[‘required’];
$type = $question[‘type’];
$answers = $question[‘answers’];
//we want to replace the keys with the values
$new_answers = array();
foreach($answers as $key => $value){
$new_answers[$value] = $value;
}
$field_identifier = $meeting_id.’-‘.$number_to_use.’-‘.$field_title_translated;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-‘.$field_title_for_class);
// $label = str_replace(‘_’,’ ‘,$field_name);
// $label = ucwords($label);
//translate the field type
if($type == ‘short’){
$field_type = ‘text’;
}
if($type == ‘multiple’){
$field_type = ‘radio’;
}
if($type == ‘single_radio’){
$field_type = ‘radio’;
}
if($type == ‘single_dropdown’ || $type == ‘single’){
$field_type = ‘select’;
}
$select_types = array(‘multiple’,’single_radio’,’single_dropdown’,’single’);
$temp_array = array(
‘type’ => $field_type,
‘required’ => $required,
‘class’ => $field_class,
‘label’ => __($field_title,’woocommerce-to-zoom-meetings’),
);
if(in_array($type,$select_types)){
$temp_array[‘options’] = $new_answers;
}
woocommerce_form_field( $field_identifier,$temp_array , $checkout->get_value( $field_identifier ));
}
}
echo ‘</div>’;
} //end for each quantity
echo ‘</div>’;
}
}
}
}
/**
*
*
*
* Adds custom fields to the woocommerce checkout area (recordings)
*/
add_action( ‘woocommerce_after_order_notes’, ‘woocommerce_to_zoom_meetings_checkout_fields_recordings’ );
function woocommerce_to_zoom_meetings_checkout_fields_recordings( $checkout ) {
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
//do pre-query to find out whether meetings exist for the purpose of the button
$recordings_exist = false;
foreach ( $cart as $item_key => $item_value ) {
$cart_product_id = $item_value[ ‘data’ ] -> get_id();
$recording_id = get_post_meta( $cart_product_id, ‘zoom_recording_selection’, true );
if(strlen($recording_id)>0){
$recordings_exist = true;
}
}
//add class to specific areas to hide it
$hide_checkout_form = get_option(‘wc_settings_zoom_meetings_hide_checkout_form’);
if($hide_checkout_form == ‘yes’){
$additional_class = ‘zoom-meetings-hide-checkout-form’;
} else {
$additional_class = »;
}
//we need to capture unique data
$meeting_combos_used = array();
//do button if meetings exist
if($recordings_exist){
echo ‘<button class=»woocommerce-to-zoom-meetings-copy-from-billing ‘.$additional_class.'»>’.__(‘Copy from billing details’,’woocommerce-to-zoom-meetings’).'</button>’;
}
//loop through each item in the cart
foreach ( $cart as $item_key => $item_value ) {
//get variables for the cart item
$cart_product_id = $item_value[ ‘data’ ] -> get_id();
$cart_product_title = $item_value[ ‘data’ ] -> get_name();
$cart_product_slug = $item_value[ ‘data’ ]->get_slug();
$cart_product_qty = $item_value[‘quantity’];
$recording_data = woocommerce_to_zoom_meetings_get_recordings();
//if it is a booking instead of using the quantity use the persons instead
if(array_key_exists(‘booking’,$item_value)){
$number_of_persons = $item_value[‘booking’][‘Persons’];;
//we need to make sure there’s at least 1 registrant!
if($number_of_persons == 0){
$number_of_persons = 1;
}
$cart_product_qty = $number_of_persons;
}
$recording_id = get_post_meta( $cart_product_id, ‘zoom_recording_selection’, true );
if(strlen($recording_id)>0){
$multiple_recordings = explode(‘,’,$recording_id);
foreach($multiple_recordings as $recording_id){
// var_dump($meeting_id);
echo ‘<div class=»zoom-meeting-section» style=»margin-top: 30px;»>’;
do_action( ‘woocommerce_to_zoom_meetings_before_product_title’,$item_value );
//do heading
// echo ‘<h3 class=»‘.$additional_class.'»>’.$cart_product_title.'</h3>’;
echo ‘<h3 class=»‘.$additional_class.'»>’.apply_filters(‘woocommerce_to_zoom_meeting_title_recording’,$recording_data[$recording_id]).'</h3>’;
do_action( ‘woocommerce_to_zoom_meetings_after_product_title’,$item_value );
//lets get the registration fields for the meeting
$registration_fields = woocommerce_to_zoom_meetings_get_recording_registration_fields($recording_id);
// var_dump($registration_fields);
//lets now loop through each registrant by using the QTY as a guide
for ($i = 1 ; $i <= $cart_product_qty; $i++){
if(!array_key_exists($recording_id,$meeting_combos_used)){
$meeting_combos_used[$recording_id] = 0;
}
$meeting_combos_used[$recording_id] = $meeting_combos_used[$recording_id]+1;
$number_to_use = $meeting_combos_used[$recording_id];
echo ‘<div class=»zoom-meeting-registrant-container ‘.$additional_class.’-‘.$number_to_use.'»>’;
echo ‘<strong class=»zoom-meeting-registrant-section»>’.__(‘registrant’,’woocommerce-to-zoom-meetings’).’ ‘.$number_to_use.'</strong>’;
//first we need to do the required fields which is the first name and email
//DO FIRST NAME
$field_identifier = $recording_id.’-‘.$number_to_use.’-first_name’;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-first_name first_name’);
$field_options = array();
woocommerce_form_field( $field_identifier, array(
‘type’ => ‘text’,
‘required’ => true,
‘class’ => $field_class,
‘label’ => __(‘First Name’,’woocommerce-to-zoom-meetings’),
‘maxlength’ => false,
‘placeholder’ => __(»,’woocommerce-to-zoom-meetings’),
‘options’ => $field_options,
), $checkout->get_value( $field_identifier ));
//DO LAST NAME
$field_identifier = $recording_id.’-‘.$number_to_use.’-last_name’;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-last_name last_name’);
$field_options = array();
woocommerce_form_field( $field_identifier, array(
‘type’ => ‘text’,
‘required’ => true,
‘class’ => $field_class,
‘label’ => __(‘Last Name’,’woocommerce-to-zoom-meetings’),
‘maxlength’ => false,
‘placeholder’ => __(»,’woocommerce-to-zoom-meetings’),
‘options’ => $field_options,
), $checkout->get_value( $field_identifier ));
//DO EMAIL
$field_identifier = $recording_id.’-‘.$number_to_use.’-email’;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-email email’);
$field_options = array();
woocommerce_form_field( $field_identifier, array(
‘type’ => ‘text’,
‘required’ => true,
‘class’ => $field_class,
‘label’ => __(‘Email’,’woocommerce-to-zoom-meetings’),
‘maxlength’ => false,
‘placeholder’ => __(»,’woocommerce-to-zoom-meetings’),
‘options’ => $field_options,
), $checkout->get_value( $field_identifier ));
//now we need to do our API registration fields
//lets do our standard fields first
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0 && strpos($recording_id, ‘WooCommerceBookings’) === false){
$field_type_helper = array(
// ‘last_name’ => ‘text’,
‘address’ => ‘text’,
‘city’ => ‘text’,
‘country’ => ‘country’,
‘zip’ => ‘text’,
‘state’ => ‘state’,
‘phone’ => ‘tel’,
‘industry’ => ‘text’,
‘org’ => ‘text’,
‘job_title’ => ‘text’,
‘purchasing_time_frame’ => ‘text’,
‘role_in_purchase_process’ => ‘text’,
‘no_of_employees’ => ‘number’,
‘comments’ => ‘text’,
);
foreach($registration_fields[‘questions’] as $question){
$field_name = $question[‘field_name’];
//dont do last name field because we have already done it
if($field_name != ‘last_name’){
$required = $question[‘required’];
$field_identifier = $recording_id.’-‘.$number_to_use.’-‘.$field_name;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-‘.$field_name.’ ‘.$field_name);
$label = str_replace(‘_’,’ ‘,$field_name);
$label = ucwords($label);
woocommerce_form_field( $field_identifier, array(
‘type’ => $field_type_helper[$field_name],
‘required’ => $required,
‘class’ => $field_class,
‘label’ => __($label,’woocommerce-to-zoom-meetings’),
), $checkout->get_value( $field_identifier ));
}
}
}
//now lets do our custom questions
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0 && strpos($recording_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘custom_questions’] as $question){
$field_title = $question[‘title’];
$field_title_translated = base64_encode($field_title);
$field_title_for_class = strip_tags($field_title);
$field_title_for_class = strtolower($field_title_for_class);
$field_title_for_class = str_replace(‘ ‘,’-‘,$field_title_for_class);
$field_title_for_class = str_replace(‘(‘,»,$field_title_for_class);
$field_title_for_class = str_replace(‘)’,»,$field_title_for_class);
$required = $question[‘required’];
$type = $question[‘type’];
$answers = $question[‘answers’];
//we want to replace the keys with the values
$new_answers = array();
foreach($answers as $key => $value){
$new_answers[$value] = $value;
}
$field_identifier = $recording_id.’-‘.$number_to_use.’-‘.$field_title_translated;
$field_class = array(‘form-row-wide ‘.$field_identifier.’ ‘.$number_to_use.’-‘.$field_title_for_class);
// $label = str_replace(‘_’,’ ‘,$field_name);
// $label = ucwords($label);
//translate the field type
if($type == ‘short’){
$field_type = ‘text’;
}
if($type == ‘multiple’){
$field_type = ‘radio’;
}
if($type == ‘single_radio’){
$field_type = ‘radio’;
}
if($type == ‘single_dropdown’ || $type == ‘single’){
$field_type = ‘select’;
}
$select_types = array(‘multiple’,’single_radio’,’single_dropdown’,’single’);
$temp_array = array(
‘type’ => $field_type,
‘required’ => $required,
‘class’ => $field_class,
‘label’ => __($field_title,’woocommerce-to-zoom-meetings’),
);
if(in_array($type,$select_types)){
$temp_array[‘options’] = $new_answers;
}
woocommerce_form_field( $field_identifier,$temp_array , $checkout->get_value( $field_identifier ));
}
}
echo ‘</div>’;
} //end for each quantity
echo ‘</div>’;
}
}
}
}
/**
*
*
*
* Save the data
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘woocommerce_to_zoom_meetings_save_checkout_fields’ );
function woocommerce_to_zoom_meetings_save_checkout_fields( $order_id ) {
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
//we need to capture unique data
$meeting_combos_used = array();
//start the main loop
foreach ( $cart as $item_key => $item_value ) {
$cart_product_id = $item_value[ ‘data’ ]->get_id();
$cart_product_qty = $item_value[‘quantity’];
//if it is a booking instead of using the quantity use the persons instead
if(array_key_exists(‘booking’,$item_value)){
$number_of_persons = $item_value[‘booking’][‘Persons’];;
// //we need to make sure there’s at least 1 registrant!
// if($number_of_persons == 0){
// $number_of_persons = 1;
// }
$cart_product_qty = $number_of_persons + 1;
}
$meeting_id = get_post_meta( $cart_product_id, ‘zoom_meeting_selection’, true );
// $meeting_id = woocommerce_to_zoom_meetings_sanitize_meeting_id($meeting_id);
if(strlen($meeting_id)>0){
$multiple_meetings = explode(‘,’,$meeting_id);
foreach($multiple_meetings as $meeting_id){
$registration_fields = woocommerce_to_zoom_meetings_get_meeting_registration_fields($meeting_id);
for ($i = 1 ; $i <= $cart_product_qty; $i++){
if(!array_key_exists($meeting_id,$meeting_combos_used)){
$meeting_combos_used[$meeting_id] = 0;
}
$meeting_combos_used[$meeting_id] = $meeting_combos_used[$meeting_id]+1;
$number_to_use = $meeting_combos_used[$meeting_id];
$order_meta = array();
//do a fix for woocommerce bookings
$meeting_id = str_replace(‘WooCommerce Bookings’,’WooCommerce_Bookings’,$meeting_id);
//do compulsory fields
//first name
$field_identifier = $meeting_id.’-‘.$number_to_use.’-first_name’;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[‘first_name’] = sanitize_text_field($_POST[$field_identifier]);
}
//last name
$field_identifier = $meeting_id.’-‘.$number_to_use.’-last_name’;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[‘last_name’] = sanitize_text_field($_POST[$field_identifier]);
}
//email
$field_identifier = $meeting_id.’-‘.$number_to_use.’-email’;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[‘email’] = sanitize_text_field($_POST[$field_identifier]);
}
//do standard fields
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0 && strpos($meeting_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘questions’] as $question){
$field_name = $question[‘field_name’];
$field_identifier = $meeting_id.’-‘.$number_to_use.’-‘.$field_name;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[$field_name] = sanitize_text_field($_POST[$field_identifier]);
}
}
}
//do custom fields
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0 && strpos($meeting_id, ‘WooCommerceBookings’) === false){
$temp_array = array();
foreach($registration_fields[‘custom_questions’] as $question){
$field_title = $question[‘title’];
$field_title_translated = base64_encode($field_title);
$field_identifier = $meeting_id.’-‘.$number_to_use.’-‘.$field_title_translated;
if ( !empty($_POST[$field_identifier]) ) {
array_push($temp_array,array(
‘title’ => $field_title,
‘value’ => sanitize_text_field($_POST[$field_identifier]),
));
}
}
//now add to main array
$order_meta[‘custom_questions’] = $temp_array;
}
update_post_meta( $order_id, ‘zoom_meeting-‘.$meeting_id.’-‘.$number_to_use, $order_meta );
}
}
}
}
}
/**
*
*
*
* Save the data (recordings)
*/
add_action( ‘woocommerce_checkout_update_order_meta’, ‘woocommerce_to_zoom_meetings_save_checkout_fields_recordings’ );
function woocommerce_to_zoom_meetings_save_checkout_fields_recordings( $order_id ) {
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
//we need to capture unique data
$meeting_combos_used = array();
//start the main loop
foreach ( $cart as $item_key => $item_value ) {
$cart_product_id = $item_value[ ‘data’ ]->get_id();
$cart_product_qty = $item_value[‘quantity’];
//if it is a booking instead of using the quantity use the persons instead
if(array_key_exists(‘booking’,$item_value)){
$number_of_persons = $item_value[‘booking’][‘Persons’];;
// //we need to make sure there’s at least 1 registrant!
// if($number_of_persons == 0){
// $number_of_persons = 1;
// }
$cart_product_qty = $number_of_persons + 1;
}
$recording_id = get_post_meta( $cart_product_id, ‘zoom_recording_selection’, true );
if(strlen($recording_id)>0){
$multiple_recordings = explode(‘,’,$recording_id);
foreach($multiple_recordings as $recording_id){
$registration_fields = woocommerce_to_zoom_meetings_get_recording_registration_fields($recording_id);
for ($i = 1 ; $i <= $cart_product_qty; $i++){
if(!array_key_exists($recording_id,$meeting_combos_used)){
$meeting_combos_used[$recording_id] = 0;
}
$meeting_combos_used[$recording_id] = $meeting_combos_used[$recording_id]+1;
$number_to_use = $meeting_combos_used[$recording_id];
$order_meta = array();
//do a fix for woocommerce bookings
$recording_id = str_replace(‘WooCommerce Bookings’,’WooCommerce_Bookings’,$recording_id);
//do compulsory fields
//first name
$field_identifier = $recording_id.’-‘.$number_to_use.’-first_name’;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[‘first_name’] = sanitize_text_field($_POST[$field_identifier]);
}
//last name
$field_identifier = $recording_id.’-‘.$number_to_use.’-last_name’;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[‘last_name’] = sanitize_text_field($_POST[$field_identifier]);
}
//email
$field_identifier = $recording_id.’-‘.$number_to_use.’-email’;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[‘email’] = sanitize_text_field($_POST[$field_identifier]);
}
//do standard fields
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0 && strpos($recording_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘questions’] as $question){
$field_name = $question[‘field_name’];
$field_identifier = $recording_id.’-‘.$number_to_use.’-‘.$field_name;
if ( !empty($_POST[$field_identifier]) ) {
$order_meta[$field_name] = sanitize_text_field($_POST[$field_identifier]);
}
}
}
//do custom fields
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0 && strpos($recording_id, ‘WooCommerceBookings’) === false){
$temp_array = array();
foreach($registration_fields[‘custom_questions’] as $question){
$field_title = $question[‘title’];
$field_title_translated = base64_encode($field_title);
$field_identifier = $recording_id.’-‘.$number_to_use.’-‘.$field_title_translated;
if ( !empty($_POST[$field_identifier]) ) {
array_push($temp_array,array(
‘title’ => $field_title,
‘value’ => sanitize_text_field($_POST[$field_identifier]),
));
}
}
//now add to main array
$order_meta[‘custom_questions’] = $temp_array;
}
update_post_meta( $order_id, ‘zoom_recording-‘.$recording_id.’-‘.$number_to_use, $order_meta );
}
}
}
}
}
/**
*
*
*
* Make required fields actually required – validation
*/
add_action( ‘woocommerce_checkout_process’, ‘woocommerce_to_zoom_meetings_require_checkout_fields’ );
function woocommerce_to_zoom_meetings_require_checkout_fields() {
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
$meeting_combos_used = array();
//start the main loop
foreach ( $cart as $item_key => $item_value ) {
$cart_product_id = $item_value[ ‘data’ ]->get_id();
$cart_product_qty = $item_value[‘quantity’];
$meeting_id = get_post_meta( $cart_product_id, ‘zoom_meeting_selection’, true );
// $meeting_id = woocommerce_to_zoom_meetings_sanitize_meeting_id($meeting_id);
if(strlen($meeting_id)>0){
$multiple_meetings = explode(‘,’,$meeting_id);
foreach($multiple_meetings as $meeting_id){
$duplicate_email_check = array();
$registration_fields = woocommerce_to_zoom_meetings_get_meeting_registration_fields($meeting_id);
for ($i = 1 ; $i <= $cart_product_qty; $i++){
if(!array_key_exists($meeting_id,$meeting_combos_used)){
$meeting_combos_used[$meeting_id] = 0;
}
$meeting_combos_used[$meeting_id] = $meeting_combos_used[$meeting_id]+1;
$number_to_use = $meeting_combos_used[$meeting_id];
//do a fix for woocommerce bookings
$meeting_id = str_replace(‘WooCommerce Bookings’,’WooCommerce_Bookings’,$meeting_id);
//do compulsory fields
//first name
$field_identifier = $meeting_id.’-‘.$number_to_use.’-first_name’;
if ( ! $_POST[$field_identifier]) {
wc_add_notice( __( ‘The first name meeting registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//last name
$field_identifier = $meeting_id.’-‘.$number_to_use.’-last_name’;
if ( ! $_POST[$field_identifier]) {
wc_add_notice( __( ‘This last name meeting registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//email
$field_identifier = $meeting_id.’-‘.$number_to_use.’-email’;
if ( ! $_POST[$field_identifier]) {
wc_add_notice( __( ‘This email meeting registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//also validate email
if(!filter_var($_POST[$field_identifier], FILTER_VALIDATE_EMAIL)){
wc_add_notice( __( ‘Please enter a valid email address.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//check if duplicate email
$do_duplicate_email_check = apply_filters(‘woocommerce_to_zoom_meetings_duplicate_check’, true);
if($do_duplicate_email_check){
if(in_array($_POST[$field_identifier], $duplicate_email_check)){
wc_add_notice( __( ‘Please enter an email adddress not already entered.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
} else {
array_push($duplicate_email_check ,$_POST[$field_identifier]);
}
}
//do standard fields
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0 && strpos($meeting_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘questions’] as $question){
$field_name = $question[‘field_name’];
$required = $question[‘required’];
$field_identifier = $meeting_id.’-‘.$number_to_use.’-‘.$field_name;
if ( !$_POST[$field_identifier] && $required) {
wc_add_notice( __( ‘This meeting registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
}
}
//do custom fields
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0 && strpos($meeting_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘custom_questions’] as $question){
$field_title = $question[‘title’];
$field_title_translated = base64_encode($field_title);
$required = $question[‘required’];
$field_identifier = $meeting_id.’-‘.$number_to_use.’-‘.$field_title_translated;
if ( !$_POST[$field_identifier] && $required) {
wc_add_notice( __( ‘This meeting registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
}
}
}
}
}
}
}
/**
*
*
*
* Make required fields actually required (recordings)
*/
add_action( ‘woocommerce_checkout_process’, ‘woocommerce_to_zoom_meetings_require_checkout_fields_recordings’ );
function woocommerce_to_zoom_meetings_require_checkout_fields_recordings() {
global $woocommerce;
$cart = $woocommerce->cart->get_cart();
$cart_items_ids = array();
//we need to capture unique data
$meeting_combos_used = array();
//start the main loop
foreach ( $cart as $item_key => $item_value ) {
$cart_product_id = $item_value[ ‘data’ ]->get_id();
$cart_product_qty = $item_value[‘quantity’];
$recording_id = get_post_meta( $cart_product_id, ‘zoom_recording_selection’, true );
if(strlen($recording_id)>0){
$multiple_recordings = explode(‘,’,$recording_id);
foreach($multiple_recordings as $recording_id){
$registration_fields = woocommerce_to_zoom_meetings_get_recording_registration_fields($recording_id);
for ($i = 1 ; $i <= $cart_product_qty; $i++){
if(!array_key_exists($recording_id,$meeting_combos_used)){
$meeting_combos_used[$recording_id] = 0;
}
$meeting_combos_used[$recording_id] = $meeting_combos_used[$recording_id]+1;
$number_to_use = $meeting_combos_used[$recording_id];
//do a fix for woocommerce bookings
$recording_id = str_replace(‘WooCommerce Bookings’,’WooCommerce_Bookings’,$recording_id);
//do compulsory fields
//first name
$field_identifier = $recording_id.’-‘.$number_to_use.’-first_name’;
if ( ! $_POST[$field_identifier]) {
wc_add_notice( __( ‘The first name recording registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//last name
$field_identifier = $recording_id.’-‘.$number_to_use.’-last_name’;
if ( ! $_POST[$field_identifier]) {
wc_add_notice( __( ‘This last name recording registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//email
$field_identifier = $recording_id.’-‘.$number_to_use.’-email’;
if ( ! $_POST[$field_identifier]) {
wc_add_notice( __( ‘This email recording registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//also validate email
if(!filter_var($_POST[$field_identifier], FILTER_VALIDATE_EMAIL)){
wc_add_notice( __( ‘Please enter a valid email address.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
//do standard fields
if(is_array($registration_fields) && count($registration_fields[‘questions’])>0 && strpos($recording_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘questions’] as $question){
$field_name = $question[‘field_name’];
$required = $question[‘required’];
$field_identifier = $recording_id.’-‘.$number_to_use.’-‘.$field_name;
if ( !$_POST[$field_identifier] && $required) {
wc_add_notice( __( ‘This recording registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
}
}
//do custom fields
if(is_array($registration_fields) && count($registration_fields[‘custom_questions’])>0 && strpos($recording_id, ‘WooCommerceBookings’) === false){
foreach($registration_fields[‘custom_questions’] as $question){
$field_title = $question[‘title’];
$field_title_translated = base64_encode($field_title);
$required = $question[‘required’];
$field_identifier = $recording_id.’-‘.$number_to_use.’-‘.$field_title_translated;
if ( !$_POST[$field_identifier] && $required) {
wc_add_notice( __( ‘This meeting registration field is required.’,’woocommerce-to-zoom-meetings’ ), ‘error’ );
}
}
}
}
}
}
}
}
?>
woocommerce-product-settings.php