is_type( 'bookable' ) ) {
if($product_enable_book==1) {
if($product_days_to_sel==2) {
if((sanitize_text_field($_POST['start_date'])=="")||(sanitize_text_field($_POST['end_date'])=="")) {
$data = new WP_Error( 'error', sprintf( __( 'Enter Date correctly', 'custom-options'),"" ) );
wc_add_notice( $data->get_error_message(), 'error' );
$data_msg = 1;
}
}
else if(sanitize_text_field($_POST['start_date'])=="") {
$data = new WP_Error( 'error', sprintf( __( 'Enter Date correctly', 'custom-options'),"" ) );
wc_add_notice( $data->get_error_message(), 'error' );
$data_msg = 1;
}
}
}
if($data_msg == 1) {
return false;
}
return $passed;
}
function phoen_arbpw_add_cart_item($cart_item_data) {
return $cart_item_data;
}
function phoen_arbpw_get_item_data( $other_data, $cart_item_data ) {
$product_gen_settings=get_post_meta( $cart_item_data['product_id'], 'phoen_arbpw_calander_mode', true );
$product_enable_book=isset($product_gen_settings['product_enable_book'])?$product_gen_settings['product_enable_book']:'';
$product_days_to_sel=isset($product_gen_settings['product_days_to_sel'])?$product_gen_settings['product_days_to_sel']:'';
if ( ! empty( $cart_item_data['phoeniixx_booking_dates'] ) ) {
foreach ( $cart_item_data['phoeniixx_booking_dates'] as $options ) {
if($product_enable_book==1) {
if($product_days_to_sel==2) {
echo " "." From: ".$options['start_value'];
echo " "." To: ".$options['end_value'];
}
else if($product_days_to_sel==1){
echo " "." DateTime: ".$options['start_value'];
}
}
}
}
return $other_data;
}
function phoen_arbpw_add_to_cart_product( $cart_item_data,$product_id ) {
$val_post = isset($_POST['start_date'])?sanitize_text_field($_POST['start_date']):'';
$end_val=isset($_POST['end_date'])?sanitize_text_field($_POST['end_date']):'';
if (strpos($val_post, 'AM') !== false || strpos($val_post, 'PM') !== false) {
$val_post=date("y-m-d").' '.$val_post;
$end_val=date("y-m-d").' '.$end_val;
$val_post = date('Y-m-d H:i:s', strtotime($val_post));
$end_val = date('Y-m-d H:i:s', strtotime($end_val));
}
if($val_post != '') {
$data[] = array(
'start_value' => $val_post,
'end_value'=>$end_val
);
$cart_item_data['phoeniixx_booking_dates'] = $data;
}
return $cart_item_data;
}
function phoen_arbpw_calculate_extra_feea($cart_object ) {
$old_price1='';
foreach ( $cart_object->cart_contents as $key => $value ) {
$_product = wc_get_product( $value['data']->get_id() );
if( $_product->is_type( 'bookable' ) ) {
$old_price1=get_post_meta($value['data']->get_id(), 'phoen_regular_price',true);
$product_gen_settings=get_post_meta( $value['data']->get_id() ,'phoen_arbpw_calander_mode', true );
$product_enable_book=isset($product_gen_settings['product_enable_book'])?$product_gen_settings['product_enable_book']:'';
$product_days_to_sel=isset($product_gen_settings['product_days_to_sel'])?$product_gen_settings['product_days_to_sel']:'';
$product_calc_mode=isset($product_gen_settings['product_calc_mode'])?$product_gen_settings['product_calc_mode']:'';
$pickertype=isset($product_gen_settings['pickertype'])?$product_gen_settings['pickertype']:'';
$st_date= isset($value['phoeniixx_booking_dates'][0]['start_value'])?$value['phoeniixx_booking_dates'][0]['start_value']:'';
$end_date= isset($value['phoeniixx_booking_dates'][0]['end_value'])?$value['phoeniixx_booking_dates'][0]['end_value']:'';
if($pickertype=="time"){
$dteStart = new DateTime($st_date);
$dteEnd = new DateTime($end_date);
$dteDiff_mi = $dteStart->diff($dteEnd);
$dteDiff=$dteDiff_mi->h;
}elseif($pickertype=="weekly"){
$dteStart = new DateTime($st_date);
$dteEnd = new DateTime($end_date);
$dteDiff = $dteStart->diff($dteEnd);
$dteDiff = $dteEnd->diff($dteStart)->format("%a");
$dteDiff=round($dteDiff/7);
}else{
$dteStart = new DateTime($st_date);
$dteEnd = new DateTime($end_date);
$dteDiff = $dteStart->diff($dteEnd);
$dteDiff = $dteEnd->diff($dteStart)->format("%a");
}
if($product_enable_book==1) {
if($pickertype=='time' || $pickertype=='weekly'){
if($product_days_to_sel==1){
$dteDiff=1;
}
}else{
if(($product_calc_mode=="Day")&&($product_days_to_sel==2)) {
$dteDiff+=1;
}
else if($product_days_to_sel==1) {
$dteDiff=1;
}
}
if($end_date=="") {
$dteDiff=1;
}
}
$phoen_data = ($old_price1*$dteDiff);
$value['data']->set_price($phoen_data);
}
}
}
function phoen_arbpw_order_item_meta($item_id,$values) {
if ( ! empty( $values['phoeniixx_booking_dates'] ) ) {
foreach ( $values['phoeniixx_booking_dates'] as $options ) {
if($options['end_value']!="") {
woocommerce_add_order_item_meta( $item_id,"FROM", $options['start_value'] );
woocommerce_add_order_item_meta( $item_id,"TO", $options['end_value'] );
}
else {
woocommerce_add_order_item_meta( $item_id, "DATETIME", $options['start_value'] );
}
}
}
}
function phoen_arbpw_add_price_html( $price = '', $product) {
global $product;
$_product = wc_get_product( $product->get_id() );
if( $_product->is_type( 'bookable' ) ) {
$price_html='';
$price=get_post_meta($product->get_id(), 'phoen_regular_price',true);
$price=wc_price( $price );
$product_gen_settings=get_post_meta( $product->get_id(), 'phoen_arbpw_calander_mode', true );
$product_enable_book=isset($product_gen_settings['product_enable_book'])?$product_gen_settings['product_enable_book']:'';
if(isset($product_gen_settings['pickertype']) && $product_gen_settings['pickertype']=="time") {
$product_calc_mode='Hours';
}elseif(isset($product_gen_settings['pickertype']) && $product_gen_settings['pickertype']=="weekly"){
$product_calc_mode='Week';
}else{
$product_calc_mode=isset($product_gen_settings['product_calc_mode'])?$product_gen_settings['product_calc_mode']:'';
}
if($product_enable_book==1){
$price_html = __('/'.$product_calc_mode, 'phoen_arbpw');
}
if($price!="") {
$price .= '' . $price_html . '';
}
}
return $price;
}
function phoen_arbpw_get_cart_item_from_session($cart_item_data, $values) {
if ( ! empty( $values['phoeniixx_booking_dates'] ) ) {
$cart_item_data['phoeniixx_booking_dates'] = $values['phoeniixx_booking_dates'];
$cart_item_data = phoen_arbpw_add_cart_item( $cart_item_data );
}
return $cart_item_data;
}
add_filter( 'product_type_selector', 'phoen_add_custom_product_type' );
function phoen_add_custom_product_type( $types ){
$types[ 'bookable' ] = __( 'Bookable Product' ,'phoen_arbpw');
return $types;
}
add_filter( 'woocommerce_product_data_tabs', 'phoen_appointment_booking_tab' );
add_action( 'product_type_options', 'phoen_bookable_product_type_options' );
function phoen_bookable_product_type_options($options){
$options['virtual']['wrapper_class'] = 'show_if_simple_bookable';
return $options;
}
add_action( 'plugins_loaded', 'phoen_appointment_custom_product_type' );
function phoen_appointment_custom_product_type(){
// declare the product class
class WC_Product_bookable extends WC_Product{
public function __construct( $product ) {
$this->product_type = 'bookable';
$this->virtual = 'yes';
parent::__construct( $product );
// add additional functions here
}
}
}
function phoen_appointment_booking_tab( $tabs) {
$tabs['bookable'] =array(
'label' => __( 'Booking', 'phoen-arbpw' ),
'target' => 'phoen_bookable_options',
'class' => ('show_if_bookable'),
'priority' => 10,
);
$tabs['availability'] =array(
'label' => __( 'Availability', 'phoen-arbpw' ),
'target' => 'phoen_bookable_options_availability',
'class' => ('show_if_bookable'),
'priority' => 20,
);
return $tabs;
}
//edit price tag e.g /day or /night
add_filter( 'woocommerce_get_price_html', 'phoen_arbpw_add_price_html' , 10, 2 );
//calculate price according to per unit include additional or custom cahrge
add_action( 'woocommerce_before_calculate_totals', 'phoen_arbpw_calculate_extra_feea', 1, 1 );
// Get item data to display on cart page after checkout on product column
add_filter( 'woocommerce_get_item_data', 'phoen_arbpw_get_item_data' , 10, 2 );
//Stores options value in cart
add_filter( 'woocommerce_add_cart_item_data', 'phoen_arbpw_add_to_cart_product' , 10, 2 );
//return options value on cart in product column during session
add_filter( 'woocommerce_add_cart_item', 'phoen_arbpw_add_cart_item' , 20, 1 );
// it takes value from checkout to order
add_filter( 'woocommerce_get_cart_item_from_session', 'phoen_arbpw_get_cart_item_from_session' , 20, 2 );
//add textbox to product page
add_action( 'woocommerce_before_add_to_cart_button', 'phoen_arbpw_calander_on_product', 10, 0 );
// Validate when adding to cart
add_filter( 'woocommerce_add_to_cart_validation', 'phoen_arbpw_validate_add_cart_product' , 10, 3 );
//order page
add_action( 'woocommerce_add_order_item_meta', 'phoen_arbpw_order_item_meta' , 10, 2 );
include_once(PHOEN_ARBPRPLUGPATH.'includes/phoeniixx_arbpw_product.php');
}else{
add_action('admin_notices', 'phoen_arbpw_admin_notice');
function phoen_arbpw_admin_notice() {
global $current_user ;
$user_id = $current_user->ID;
/* Check that the user hasn't already clicked to ignore the message */
if ( ! get_user_meta($user_id, 'phoen_arbpw_ignore_notice') ) {
echo '
';
printf(__('Woocommerce Appointment and Booking System could not detect an active Woocommerce plugin. Make sure you have activated it. | Hide Notice'), '?phoen_arbpw_nag_ignore=0');
echo "
";
}
}
add_action('admin_init', 'phoen_arbpw_nag_ignore');
function phoen_arbpw_nag_ignore() {
global $current_user;
$user_id = $current_user->ID;
/* If user clicks to ignore the notice, add that to their user meta */
if ( isset($_GET['phoen_arbpw_nag_ignore']) && '0' == $_GET['phoen_arbpw_nag_ignore'] ) {
add_user_meta($user_id, 'phoen_arbpw_ignore_notice', 'true', true);
}
}
}?>