Created
December 8, 2022 06:49
-
-
Save digamber89/96955668f37ee5fb06ea833111b1bf94 to your computer and use it in GitHub Desktop.
Zoom WC Bookings - get join links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Codemanas\VczapiBookingsMod; | |
class VCZAPIBookingsMod { | |
public static $instance = null; | |
public static function get_instance() { | |
return is_null( self::$instance ) ? self::$instance = new self() : self::$instance; | |
} | |
protected function __construct() { | |
add_shortcode( 'vczapi_bookings_order_app_link', [ $this, 'vczapi_bookings_order_app_link' ] ); | |
add_shortcode( 'vczapi_bookings_order_web_link', [ $this, 'vczapi_bookings_order_web_link' ] ); | |
} | |
private function vczapi_mod_get_browser_join_link( $meeting_id, $password = false ) { | |
$link = get_post_type_archive_link( 'zoom-meetings' ); | |
$encrypt_meeting_id = vczapi_encrypt_decrypt( 'encrypt', $meeting_id ); | |
if ( ! empty( $password ) ) { | |
$encrypt_pwd = vczapi_encrypt_decrypt( 'encrypt', $password ); | |
return add_query_arg( array( 'pak' => $encrypt_pwd, 'join' => $encrypt_meeting_id, 'type' => 'meeting' ), $link ); | |
} else { | |
return add_query_arg( array( 'join' => $encrypt_meeting_id, 'type' => 'meeting' ), $link ); | |
} | |
} | |
public function vczapi_bookings_order_web_link( $atts ) { | |
$atts = shortcode_atts( [ | |
'order_id' => null, | |
'booking_id' => null, | |
], $atts ); | |
ob_start(); | |
if ( $atts['order_id'] == null && $atts['booking_id'] == null ) { | |
return ob_get_clean(); | |
} | |
if ( $atts['booking_id'] != null ) { | |
$meeting = get_post_meta( $atts['booking_id'], '_vczapi_woo_addon_meeting_details', true ); | |
$meeting = ! empty( $meeting ) ? json_decode( $meeting ) : false; | |
if ( $meeting ) { | |
$password = ! empty( $meeting->password ) ? $meeting->password : false; | |
echo $this->vczapi_mod_get_browser_join_link( $meeting->id, $password ); | |
} | |
} elseif ( $atts['order_id'] != null ) { | |
$order = wc_get_order( $atts['order_id'] ); | |
if ( $order !== false ) { | |
$items = $order->get_items(); | |
foreach ( $items as $item_id => $item ) { | |
$booking_ids = \WC_Booking_Data_Store::get_booking_ids_from_order_item_id( $item_id ); | |
if ( ! empty( $booking_ids ) ) { | |
foreach ( $booking_ids as $booking_id ) { | |
$meeting = get_post_meta( $booking_id, '_vczapi_woo_addon_meeting_details', true ); | |
$meeting = ! empty( $meeting ) ? json_decode( $meeting ) : false; | |
if ( $meeting ) { | |
$password = ! empty( $meeting->password ) ? $meeting->password : false; | |
echo $this->vczapi_mod_get_browser_join_link( $meeting->id, $password ); | |
} | |
} | |
} | |
} | |
} | |
} | |
return ob_get_clean(); | |
} | |
public function vczapi_bookings_order_app_link( $atts ) { | |
$atts = shortcode_atts( [ | |
'order_id' => null, | |
'booking_id' => null, | |
], $atts ); | |
ob_start(); | |
if ( $atts['order_id'] == null && $atts['booking_id'] == null ) { | |
return ob_get_clean(); | |
} | |
if ( $atts['booking_id'] != null ) { | |
$meeting = get_post_meta( $atts['booking_id'], '_vczapi_woo_addon_meeting_details', true ); | |
$meeting = ! empty( $meeting ) ? json_decode( $meeting ) : false; | |
if ( isset( $meeting->join_url ) ) { | |
echo esc_url( $meeting->join_url ); | |
} | |
} elseif ( $atts['order_id'] != null ) { | |
$order = wc_get_order( $atts['order_id'] ); | |
if ( $order !== false ) { | |
$items = $order->get_items(); | |
foreach ( $items as $item_id => $item ) { | |
$booking_ids = \WC_Booking_Data_Store::get_booking_ids_from_order_item_id( $item_id ); | |
if ( ! empty( $booking_ids ) ) { | |
foreach ( $booking_ids as $booking_id ) { | |
$meeting = get_post_meta( $booking_id, '_vczapi_woo_addon_meeting_details', true ); | |
$meeting = ! empty( $meeting ) ? json_decode( $meeting ) : false; | |
if ( isset( $meeting->join_url ) ) { | |
echo esc_url( $meeting->join_url ); | |
} | |
} | |
} | |
} | |
} | |
} | |
return ob_get_clean(); | |
} | |
} | |
VCZAPIBookingsMod::get_instance(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment