1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
<?php
if ( !class_exists( 'BKAP_OPC_Addon' ) ) {
class BKAP_OPC_Addon {
function __construct() {
add_action( 'wcopc_after_add_to_cart_button', array( &$this, 'bkap_opc_add_booking_button' ), 10, 1 );
add_action( 'woocommerce_before_single_product_summary', array( &$this, 'bkap_opc_include_scripts_styles' ), 50, 1 );
}
public function bkap_opc_include_scripts_styles( $page_id ) {
global $product;
$product_id = $product->get_id();
woocommerce_booking::include_frontend_scripts_js( $product_id );
woocommerce_booking::inlcude_frontend_scripts_css( $product_id );
self::bkap_opc_load_scripts( $product, $product_id );
}
public function bkap_opc_add_booking_button( $product ) {
if ( 'simple' === $product->get_type() ) {
$product_id = $product->get_id();
$variation_id = '';
$modal_id = $product_id;
}else if ( 'variation' === $product->get_type() ) {
$product_id = $product->get_parent_id();
$variation_id = $product->get_id();
$modal_id = $variation_id;
}
$is_bookable = bkap_common::bkap_get_bookable_status( $product_id );
if ( $is_bookable ) {
printf( '<input type="button" onclick=bkap_edit_booking_class.bkap_edit_bookings(%d,"%s") value="%s" class="bkap-opc-button">', $product_id, $modal_id, __( 'Book Now', 'woocommerce-booking' ) );
$page_type = '';
if ( is_cart() ) {
$page_type = 'cart';
}else if ( is_checkout() ) {
$page_type = 'checkout';
}
$localized_array = array(
'bkap_booking_params' => array(),
'bkap_cart_item' => '',
'bkap_cart_item_key' => $modal_id,
'bkap_page_type' => $page_type
);
$additional_addon_data = '';
$booking_details = array(
'date' => '',
'hidden_date' => '',
'date_checkout' => '',
'hidden_date_checkout' => '',
'price' => '',
);
bkap_edit_bookings_class::bkap_load_template(
$booking_details,
$product,
$product_id,
$localized_array,
$modal_id,
$variation_id,
$additional_addon_data );
self::bkap_opc_load_scripts( $product, $product_id );
}
}
public static function bkap_opc_load_scripts( $product, $product_id ) {
$localized_params = array( 'product_id' => $product_id );
wp_register_script(
"bkap-opc-add-booking",
plugins_url( '/js/bkap-opc-add-booking.js', __FILE__ ),
'',
'',
false );
wp_localize_script( "bkap-opc-add-booking", "bkap_opc_add_booking_$product_id", $localized_params );
wp_enqueue_script( "bkap-opc-add-booking" );
}
}
}
$bkap_opc_addon = new BKAP_OPC_Addon();