Advertisement
Guest User

Untitled

a guest
May 20th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 27.80 KB | None | 0 0
  1. <?php if ( !defined( 'ABSPATH' ) ) exit();
  2.  
  3. /**
  4.  * Returns every date between two dates as an array
  5.  * @param string $startDate the start of the date range
  6.  * @param string $endDate the end of the date range
  7.  * @param string $format DateTime format, default is Y-m-d
  8.  * @return array returns every date between $startDate and $endDate, formatted as "Y-m-d"
  9.  */
  10.  
  11.  
  12. function ovacrs_createDatefull($start, $end, $format = "Y-m-d"){
  13.    
  14.     $dates = array();
  15.     while($start <= $end){
  16.         array_push( $dates, date( $format, $start) );
  17.         $start += 86400;
  18.     }
  19.  
  20.     return $dates;
  21. }
  22.  
  23. function total_between_2_days( $start, $end){
  24.     return floor( abs( strtotime($end) - strtotime($start) ) / (60*60*24) );
  25. }
  26.  
  27.  
  28.  
  29.  
  30. function ovacrs_array_flatten($array) {
  31.   if (!is_array($array)) {
  32.     return FALSE;
  33.   }
  34.   $result = array();
  35.   foreach ($array as $key => $value) {
  36.     if (is_array($value)) {
  37.       $result = array_merge($result, ovacrs_array_flatten($value));
  38.     }
  39.     else {
  40.       $result[$key] = $value;
  41.     }
  42.   }
  43.   return $result;
  44. }
  45.  
  46.  
  47.  
  48. function get_order_rent_time( $product_id, $order_status = array( 'wc-completed' ) ){
  49.  
  50.  
  51.     global $wpdb;
  52.  
  53.     $order_date = $order_date_bg = $dates_avaiable = array();
  54.     $total_each_day = array();
  55.  
  56.     $count_car_in_store = get_post_meta( $product_id, 'ovacrs_car_count', true );
  57.    
  58.     $orders_ids = $wpdb->get_col("
  59.        SELECT Distinct order_items.order_id
  60.        FROM {$wpdb->prefix}woocommerce_order_items as order_items
  61.        LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
  62.        LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
  63.        WHERE posts.post_type = 'shop_order'
  64.        AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' )
  65.        AND order_items.order_item_type = 'line_item'
  66.        AND order_item_meta.meta_key = '_product_id'
  67.        AND order_item_meta.meta_value = '$product_id'
  68.    ");
  69.  
  70.  
  71.     foreach ($orders_ids as $key => $value) {
  72.  
  73.         // Get Order Detail by Order ID
  74.         $order = wc_get_order($value);
  75.  
  76.         // Get Meta Data type line_item of Order
  77.         $order_line_items = $order->get_items( apply_filters( 'woocommerce_purchase_order_item_types', 'line_item' ) );
  78.        
  79.         // For Meta Data
  80.         foreach ( $order_line_items as $item_id => $item ) {
  81.  
  82.             $ovacrs_pickup_date_store = $ovacrs_pickoff_date_store = '';
  83.  
  84.             // Get value of pickup date, pickoff date
  85.             foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
  86.                 if( $meta->key == 'ovacrs_pickup_date' ){
  87.                     $ovacrs_pickup_date_store = strtotime( str_replace('/', '-', $meta->value) );
  88.                 }
  89.                 if( $meta->key == 'ovacrs_pickoff_date' ){
  90.                     $ovacrs_pickoff_date_store = strtotime( str_replace('/', '-', $meta->value) );
  91.                 }
  92.             }
  93.  
  94.             if( $ovacrs_pickoff_date_store >= current_time( 'timestamp' ) ){
  95.  
  96.  
  97.                 $start_date = date( 'Y-m-d', $ovacrs_pickup_date_store );
  98.                 $end_date = date( 'Y-m-d', $ovacrs_pickoff_date_store );
  99.  
  100.                 $total_between_2_days = total_between_2_days( $start_date, $end_date );
  101.  
  102.  
  103.  
  104.                 if( $total_between_2_days == 0 ){ // In a day
  105.  
  106.                     $item =  array(  'start' => date( 'Y-m-d H:i', $ovacrs_pickup_date_store ),
  107.                              'end' => date( 'Y-m-d H:i', $ovacrs_pickoff_date_store ),
  108.                              'title' => date_i18n( 'H:i', $ovacrs_pickup_date_store ).'-'.date_i18n( 'H:i', $ovacrs_pickoff_date_store )
  109.                      );
  110.                     array_push( $dates_avaiable, $item );
  111.                     array_push( $total_each_day, date( 'Y-m-d', $ovacrs_pickup_date_store )  );
  112.  
  113.                 }else if( $total_between_2_days == 1 ) { // 2 day beside
  114.  
  115.                     $item =  array(  'start' => date( 'Y-m-d H:i', $ovacrs_pickup_date_store ),
  116.                              'end' => date( 'Y-m-d 24:00', $ovacrs_pickup_date_store ),
  117.                              'title' => date_i18n( 'H:i', $ovacrs_pickup_date_store ).esc_html__(' 24:00', 'ova-crs')
  118.                      );
  119.                     array_push( $dates_avaiable, $item );
  120.  
  121.  
  122.                     $item =  array(  'start' => date( 'Y-m-d 00:00', $ovacrs_pickoff_date_store ),
  123.                              'end' => date( 'Y-m-d H:i', $ovacrs_pickoff_date_store ),
  124.                              'title' => esc_html__('00:00 ', 'ova-crs').date_i18n( 'H:i', $ovacrs_pickoff_date_store )
  125.                      );
  126.                     array_push( $dates_avaiable, $item );
  127.  
  128.  
  129.                     array_push( $total_each_day, date( 'Y-m-d', $ovacrs_pickup_date_store )  );
  130.                     array_push( $total_each_day, date( 'Y-m-d', $ovacrs_pickoff_date_store )  );
  131.  
  132.  
  133.                 }else{ // from 3 days
  134.  
  135.                     $item =  array(  'start' => date( 'Y-m-d H:i', $ovacrs_pickup_date_store ),
  136.                              'end' => date( 'Y-m-d 24:00', $ovacrs_pickup_date_store ),
  137.                              'title' => date_i18n( 'H:i', $ovacrs_pickup_date_store ).esc_html__(' 24:00', 'ova-crs')
  138.                      );
  139.                     array_push( $dates_avaiable, $item );
  140.  
  141.  
  142.                     $item =  array(  'start' => date( 'Y-m-d 00:00', $ovacrs_pickoff_date_store ),
  143.                              'end' => date( 'Y-m-d H:i', $ovacrs_pickoff_date_store ),
  144.                              'title' => esc_html__('00:00 ', 'ova-crs').date_i18n( 'H:i', $ovacrs_pickoff_date_store )
  145.                      );
  146.                     array_push( $dates_avaiable, $item );
  147.  
  148.  
  149.                     array_push( $total_each_day, date( 'Y-m-d', $ovacrs_pickup_date_store )  );
  150.                     array_push( $total_each_day, date( 'Y-m-d', $ovacrs_pickoff_date_store )  );
  151.  
  152.  
  153.                     $date_between_start_end = ovacrs_createDatefull( strtotime( $start_date ), strtotime( $end_date ), $format='Y-m-d' );
  154.  
  155.                     // Remove first and last array
  156.                     array_shift( $date_between_start_end );
  157.                     array_pop( $date_between_start_end );
  158.  
  159.                     foreach ( $date_between_start_end as $key => $value) {
  160.  
  161.                         $item =  array(  'start' => $value,
  162.                                  'end' => $value,
  163.                                  'title' => esc_html__('00:00 24:00 ', 'ova-crs')
  164.                          );
  165.                         array_push( $dates_avaiable, $item );
  166.  
  167.                         array_push( $total_each_day, $value  );
  168.                     }
  169.  
  170.                 }
  171.  
  172.                
  173.  
  174.             }
  175.         }
  176.     }
  177.    
  178.  
  179.     $order_date_bg = ovacrs_array_flatten( $total_each_day );
  180.     $count_values = array_count_values( $order_date_bg );
  181.  
  182.  
  183.     $bg_rented = get_theme_mod( 'main_color', '#e9a31b' );
  184.     foreach ($count_values as $key => $value) {
  185.         if( $value >= $count_car_in_store ){
  186.             $item =  array(  'start' => $key,
  187.                              'end' => $key,
  188.                              'rendering' => 'background',
  189.                              'color' => $bg_rented,
  190.                              'overlap' => false,
  191.                              'title' => '',
  192.                              
  193.                      );
  194.             array_push( $dates_avaiable, $item );
  195.         }
  196.     }
  197.  
  198.     return json_encode( $dates_avaiable );
  199.  
  200. }
  201.  
  202.  
  203.  
  204.  
  205. function ovacrs_get_orders_by_product_id( $product_id, $order_status = array( 'wc-completed' ) ){
  206.     global $wpdb;
  207.    
  208.     $results = $wpdb->get_col("
  209.        SELECT order_items.order_id
  210.        FROM {$wpdb->prefix}woocommerce_order_items as order_items
  211.        LEFT JOIN {$wpdb->prefix}woocommerce_order_itemmeta as order_item_meta ON order_items.order_item_id = order_item_meta.order_item_id
  212.        LEFT JOIN {$wpdb->posts} AS posts ON order_items.order_id = posts.ID
  213.        WHERE posts.post_type = 'shop_order'
  214.        AND posts.post_status IN ( '" . implode( "','", $order_status ) . "' )
  215.        AND order_items.order_item_type = 'line_item'
  216.        AND order_item_meta.meta_key = '_product_id'
  217.        AND order_item_meta.meta_value = '$product_id'
  218.    ");
  219.  
  220.     return $results;
  221. }
  222.  
  223.  
  224. // Search Form
  225. function ovacrs_search_vehicle( $data_search ){
  226.  
  227.     $pickup_loc = isset( $data_search['ovacrs_pickup_loc'] ) ? $data_search['ovacrs_pickup_loc']: '';
  228.     $pickoff_loc = isset( $data_search['ovacrs_pickoff_loc'] ) ? $data_search['ovacrs_pickoff_loc']: '';
  229.     $ovacrs_pickup_date = isset( $data_search['ovacrs_pickup_date'] )  ? strtotime( $data_search['ovacrs_pickup_date'] ) : '';
  230.     $ovacrs_pickoff_date = isset( $data_search['ovacrs_pickoff_date'] ) ? strtotime( $data_search['ovacrs_pickoff_date'] ) : '';
  231.  
  232.     $category = isset( $data_search['cat'] ) ? $data_search['cat'] : '';
  233.     $product_type = isset( $data_search['product_type'] ) ? $data_search['product_type'] : '';
  234.  
  235.     $statuses = array( 'wc-completed', 'wc-processing', 'wc-on-hold' );
  236.  
  237.     $error = array();
  238.  
  239.     $items_id = array();
  240.  
  241.     $args_base = array(
  242.         'post_type' => 'product',
  243.         'posts_per_page' => '-1',
  244.         'post_status' => 'publish'
  245.     );
  246.  
  247.     $arg_cat = ( $category != '' ) ? array(
  248.         'taxonomy' => 'product_cat',
  249.         'field' => 'slug',
  250.         'terms' => $category
  251.     ) : array('');
  252.  
  253.     $arg_type = ( $product_type != '' ) ? array(
  254.         'taxonomy' => 'type',
  255.         'field' => 'slug',
  256.         'terms' => $product_type
  257.     ) : array('');
  258.  
  259.  
  260.     if( $arg_cat != '' && $arg_type != '' ){
  261.         $args_cat = array(
  262.             'tax_query' => array(
  263.                 'relation'  => 'AND',
  264.                 $arg_cat,
  265.                 $arg_type
  266.             )
  267.         );
  268.     }else{
  269.         $args_cat = array(
  270.             'tax_query' => array(
  271.                 array_merge( $arg_cat, $arg_type )
  272.             )
  273.         );
  274.     }
  275.    
  276.  
  277.     $args = array_merge_recursive( $args_base, $args_cat );
  278.  
  279.     // Get All products
  280.     $items = new WP_Query( $args );
  281.  
  282.     if ( $items->have_posts() ) : while ( $items->have_posts() ) : $items->the_post();
  283.        
  284.         $id = get_the_id();
  285.        
  286.         $car_using_this_time = 0;
  287.  
  288.         $ovacrs_pickup_date_store = $ovacrs_pickoff_date_store = '';
  289.  
  290.         // Total Car in the Store
  291.         $total_car_store = get_post_meta( $id, 'ovacrs_car_count', true ) ? get_post_meta( $id, 'ovacrs_car_count', true ) : 0;
  292.        
  293.         $orders_ids = ovacrs_get_orders_by_product_id( $id, $statuses );
  294.  
  295.         // For Order ID
  296.         foreach ($orders_ids as $key => $value) {
  297.  
  298.             // Get Order Detail by Order ID
  299.             $order = wc_get_order($value);
  300.  
  301.             // Get Meta Data type line_item of Order
  302.             $order_items = $order->get_items( apply_filters( 'woocommerce_purchase_order_item_types', 'line_item' ) );
  303.            
  304.             // For Meta Data
  305.             foreach ( $order_items as $item_id => $item ) {
  306.  
  307.                 // Check Line Item have item ID is Car_ID
  308.                 if( $item->get_product_id() == $id ){
  309.  
  310.                     // Get value of pickup date, pickoff date
  311.                     foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
  312.                         if( $meta->key == 'ovacrs_pickup_date' ){
  313.                             $ovacrs_pickup_date_store = strtotime( str_replace('/', '-', $meta->value) );
  314.                         }
  315.                         if( $meta->key == 'ovacrs_pickoff_date' ){
  316.                             $ovacrs_pickoff_date_store = strtotime( str_replace('/', '-', $meta->value) );
  317.                         }
  318.                     }
  319.  
  320.                     // Only compare date when "PickOff Date in Store" > "Current Time" becaue "PickOff Date Rent" have to > "Current Time"
  321.                     if( $ovacrs_pickoff_date_store >= current_time( 'timestamp' ) ){
  322.                        
  323.                         // Check rent time
  324.                         if( ! ($ovacrs_pickoff_date < $ovacrs_pickup_date_store || $ovacrs_pickoff_date_store < $ovacrs_pickup_date ) ){
  325.                             $car_using_this_time++;
  326.                         }
  327.  
  328.                     }
  329.                    
  330.                 }
  331.  
  332.             }
  333.  
  334.         }
  335.  
  336.         if( $car_using_this_time < $total_car_store ){
  337.  
  338.             $vehicle_avai = array();
  339.             $vehicle_avai_flag = false;
  340.             $vehicle_untime_flag = true;
  341.             $product_untime_flag = true;
  342.  
  343.             if( $pickup_loc != '' && get_theme_mod( 'use_loc_filter_search', 'true' ) == 'true' ){
  344.  
  345.                 $id_vehicle_available = get_post_meta( $id, 'ovacrs_id_vehicles', true );
  346.  
  347.                 if( is_array( $id_vehicle_available ) ){
  348.                     foreach ($id_vehicle_available as $key => $value) {
  349.  
  350.                         $vehicle_avai = ovacrs_get_vehicle_loc_title($value);
  351.  
  352.                         $id_vehicle_untime_startday = !empty( $vehicle_avai['untime'] ) ? strtotime( $vehicle_avai['untime']['startdate'] ) : '';
  353.                         $id_vehicle_untime_enddate  = !empty( $vehicle_avai['untime'] ) ? strtotime( $vehicle_avai['untime']['enddate'] ) : '';
  354.  
  355.                         if( $pickup_loc == $vehicle_avai['loc'] ){
  356.  
  357.                             if( ! ( $ovacrs_pickoff_date < $id_vehicle_untime_startday  ||  $id_vehicle_untime_enddate < $ovacrs_pickup_date  ) && $id_vehicle_untime_startday != '' && $id_vehicle_untime_enddate != '' ){
  358.                                 $vehicle_untime_flag = false;
  359.                                 $vehicle_avai_flag = true;
  360.  
  361.                             }else{
  362.                                 $vehicle_untime_flag = true;
  363.                                 $vehicle_avai_flag = true;
  364.                                 break;    
  365.                             }
  366.  
  367.                            
  368.  
  369.                         }
  370.                     }
  371.                 }
  372.  
  373.                 if( $vehicle_avai_flag && $vehicle_untime_flag ){
  374.  
  375.                     // Check Product Untime
  376.                     $product_untime_startdate = get_post_meta( $id, 'ovacrs_untime_startdate', true );
  377.                     $product_untime_enddate = get_post_meta( $id, 'ovacrs_untime_enddate', true );
  378.  
  379.                     if( $product_untime_startdate && $product_untime_enddate ){
  380.                         foreach ($product_untime_startdate as $key => $value) {
  381.                             if( ! ($ovacrs_pickoff_date < strtotime( $product_untime_startdate[$key] ) || strtotime( $product_untime_enddate[$key] ) < $ovacrs_pickup_date ) ){
  382.                                 $product_untime_flag = false;
  383.                                 break;
  384.                             }
  385.                         }
  386.                     }
  387.                     if( $product_untime_flag ){
  388.                         array_push($items_id, $id);    
  389.                     }
  390.                    
  391.                 }
  392.                    
  393.                    
  394.             }else{
  395.  
  396.                 $id_vehicle_available = get_post_meta( $id, 'ovacrs_id_vehicles', true );
  397.  
  398.                 if( is_array( $id_vehicle_available ) ){
  399.  
  400.                     foreach ($id_vehicle_available as $key => $value) {
  401.  
  402.                         $vehicle_avai = ovacrs_get_vehicle_loc_title($value);
  403.  
  404.                         $id_vehicle_untime_startday = !empty( $vehicle_avai['untime'] ) ? strtotime( $vehicle_avai['untime']['startdate'] ) : '';
  405.                         $id_vehicle_untime_enddate  = !empty( $vehicle_avai['untime'] ) ? strtotime( $vehicle_avai['untime']['enddate'] ) : '';
  406.  
  407.  
  408.                         if( ! ( $ovacrs_pickoff_date < $id_vehicle_untime_startday  ||  $id_vehicle_untime_enddate < $ovacrs_pickup_date  ) && $id_vehicle_untime_startday != '' && $id_vehicle_untime_enddate != '' ){
  409.                             $vehicle_untime_flag = false;
  410.                         }else{
  411.                             // Check Product Untime
  412.                             $product_untime_startdate = get_post_meta( $id, 'ovacrs_untime_startdate', true );
  413.                             $product_untime_enddate = get_post_meta( $id, 'ovacrs_untime_enddate', true );
  414.  
  415.                             if( $product_untime_startdate && $product_untime_enddate ){
  416.                                 foreach ($product_untime_startdate as $key => $value) {
  417.                                     if( ! ($ovacrs_pickoff_date < strtotime( $product_untime_startdate[$key] ) || strtotime( $product_untime_enddate[$key] ) < $ovacrs_pickup_date ) ){
  418.                                         $product_untime_flag = false;
  419.                                         break;
  420.                                     }
  421.                                 }
  422.                             }
  423.                             if( $product_untime_flag ){
  424.                                 array_push($items_id, $id);
  425.                                 break;  
  426.                             }
  427.                            
  428.                         }
  429.                     }
  430.                 }
  431.  
  432.             }
  433.            
  434.  
  435.            
  436.         }
  437.  
  438.  
  439.     endwhile; else :
  440.         return $items_id;
  441.     endif; wp_reset_postdata();
  442.    
  443.  
  444.     if( $items_id ){
  445.  
  446.         $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
  447.  
  448.         $args_product = array(
  449.             'post_type' => 'product',
  450.             'posts_per_page' => 6,
  451.             'paged' => $paged,
  452.             'post_status' => 'publish',
  453.             'post__in' => $items_id
  454.         );
  455.  
  456.         $rental_products = new WP_Query( $args_product );
  457.         return $rental_products;
  458.  
  459.     }
  460.  
  461.     return false;
  462.  
  463.  
  464. }
  465.  
  466.  
  467.  
  468.  
  469. // Check Rent by Day or Hour or both
  470. function ovacrs_get_price_type( $post_id ){
  471.     return get_post_meta( $post_id, 'ovacrs_price_type', true ) ;
  472. }
  473.  
  474. // Get value rent day
  475. function ovacrs_get_price_day( $post_id ){
  476.     return wc_price( get_post_meta( $post_id, '_regular_price', true ) );
  477. }
  478.  
  479. // Get value hour day
  480. function ovacrs_get_price_hour( $post_id ){
  481.     return wc_price( get_post_meta( $post_id, 'ovacrs_regul_price_hour', true ) );
  482. }
  483.  
  484.  
  485.  
  486. // Get all location
  487. function ovacrs_get_locations(){
  488.     $locations = new WP_Query(
  489.         array(
  490.             'post_type' => 'location',
  491.             'post_status' => 'publish',
  492.             'posts_per_page' => '-1'
  493.         )
  494.     );
  495.  
  496.     return $locations;
  497.  
  498. }
  499.  
  500. function ovacrs_get_locations_array(){
  501.     $locations = new WP_Query(
  502.         array(
  503.             'post_type' => 'location',
  504.             'post_status' => 'publish',
  505.             'posts_per_page' => '-1'
  506.         )
  507.     );
  508.     $html = array();
  509.     if($locations->have_posts() ) : while ( $locations->have_posts() ) : $locations->the_post();
  510.         global $post;
  511.         $html[ trim( get_the_title() )] = trim( get_the_title() );
  512.     endwhile; endif;wp_reset_postdata();
  513.  
  514.     return $html;
  515.  
  516. }
  517.  
  518.  
  519.  
  520. function ovacrs_get_locations_html( $name = '', $required = 'required', $selected = '' ){
  521.     $locations = new WP_Query(
  522.         array(
  523.             'post_type' => 'location',
  524.             'post_status' => 'publish',
  525.             'posts_per_page' => '-1'
  526.         )
  527.     );
  528.  
  529.     $html = '<select name="'.$name.'" class="'.$required.'" >
  530.        <option value="">'. esc_html__('Select Location', 'ova-crs').'</option>';
  531.         if($locations->have_posts() ) : while ( $locations->have_posts() ) : $locations->the_post();
  532.             global $post;
  533.             $active = ( trim( get_the_title() ) === trim( $selected ) ) ? 'selected="selected"' : '';
  534.             $html .= '<option value="'.get_the_title().'" '.$active.'>'.get_the_title().'</option>';
  535.         endwhile; endif;wp_reset_postdata();
  536.     $html .= '</select>';
  537.  
  538.     return $html;
  539.  
  540.  
  541. }
  542.  
  543. // Get all number plate
  544. function ovacrs_get_all_id_vehicles(){
  545.     $vehicle = new WP_Query(
  546.         array(
  547.             'post_type' => 'vehicle',
  548.             'post_status' => 'publish',
  549.             'posts_per_page' => '-1'
  550.         )
  551.     );
  552.  
  553.     return $vehicle;
  554.  
  555. }
  556.  
  557. function ovacrs_get_vehicle_loc_title( $id_metabox ){
  558.     $vehicle_arr = array();
  559.     $vehicle = new WP_Query(
  560.         array(
  561.             'post_type' => 'vehicle',
  562.             'post_status' => 'publish',
  563.             'posts_per_page' => 1,
  564.             'meta_query' => array(
  565.                 array(
  566.                     'key'     => 'ireca_met_id_vehicle',
  567.                     'value'   => $id_metabox,
  568.                     'compare' => '=',
  569.                 ),
  570.             ),
  571.         )
  572.     );
  573.     if($vehicle->have_posts() ) : while ( $vehicle->have_posts() ) : $vehicle->the_post();
  574.         $vehicle_arr['loc'] = get_post_meta( get_the_id(), 'ireca_met_id_vehicle_location', true );
  575.         $vehicle_arr['untime'] = get_post_meta( get_the_id(), 'ireca_met_id_vehicle_untime_from_day', true );
  576.     endwhile;endif;wp_reset_postdata();
  577.     return $vehicle_arr;
  578. }
  579.  
  580.  
  581. /* Request for booking */
  582. function ovacrs_request_booking( $data ){
  583.  
  584.     $subject = esc_html__( "Request For Booking", 'ova-crs' );
  585.  
  586.     $body = '';
  587.  
  588.     $body .= esc_html__( 'Name: ', 'ova-crs' ).$data['name'].'<br/>';
  589.     $body .= esc_html__( 'Email: ', 'ova-crs' ).$data['email'].'<br/>';
  590.  
  591.     if( get_theme_mod( 'rd_rbf_show_number', 'true' ) == 'true' ){
  592.         $body .= esc_html__( 'Phone: ', 'ova-crs' ).$data['number'].'<br/>';
  593.     }
  594.  
  595.     if( get_theme_mod( 'rd_rbf_show_address', 'true' ) == 'true' ){
  596.         $body .= esc_html__( 'Address: ', 'ova-crs' ).$data['address'].'<br/>';
  597.     }
  598.  
  599.     if( get_theme_mod( 'rd_rbf_show_pickup_loc', 'true' ) == 'true' ){
  600.         $body .= esc_html__( 'Pick-up Location: ', 'ova-crs' ).$data['ovacrs_pickup_loc'].'<br/>';
  601.     }
  602.  
  603.     if( get_theme_mod( 'rd_rbf_show_pickoff_loc', 'true' ) == 'true' ){
  604.         $body .= esc_html__( 'Drop-off Location: ', 'ova-crs' ).$data['ovacrs_pickoff_loc'].'<br/>';
  605.     }
  606.  
  607.    
  608.     $body .= esc_html__( 'Pick-up Date: ', 'ova-crs' ).$data['pickup_date'].'<br/>';
  609.     $body .= esc_html__( 'Drop-off Date: ', 'ova-crs' ).$data['pickoff_date'].'<br/>';
  610.    
  611.  
  612.     if( get_theme_mod( 'rd_rbf_show_extra_source', 'true' ) == 'true' ){
  613.         $body .= esc_html__( 'Resource: ', 'ova-crs' );
  614.         $resource = $data['ovacrs_resource_checkboxs'] != '' ? implode(', ', $data['ovacrs_resource_checkboxs']) : '';
  615.         $body .= $resource.'<br/>';
  616.     }
  617.    
  618.  
  619.     if( get_theme_mod( 'rd_rbf_show_extra_info', 'true' ) == 'true' ){
  620.         $body .= esc_html__( 'Extra: ', 'ova-crs' ).$data['extra'].'<br/>';
  621.     }
  622.  
  623.     $mail_to = array( get_option('admin_email'), $data['email'] );
  624.  
  625.     return ovacrs_ovacrs_sendmail( $mail_to, $subject, $body );
  626.  
  627. }
  628.  
  629.  
  630. function ova_wp_mail_from(){
  631.     return get_option('admin_email');
  632. }
  633.  
  634. function ova_wp_mail_from_name(){
  635.     return esc_html__("Request For Booking", 'ova-crs');
  636. }
  637.  
  638. function ovacrs_ovacrs_sendmail( $mail_to, $subject, $body ){
  639.  
  640.     $headers = "MIME-Version: 1.0\r\n";
  641.     $headers .= "Content-Type: text/html; charset=".get_bloginfo( 'charset' )."\r\n";
  642.    
  643.     add_filter( 'wp_mail_from', 'ova_wp_mail_from' );
  644.     add_filter( 'wp_mail_from_name', 'ova_wp_mail_from_name' );
  645.  
  646.  
  647.     if( wp_mail($mail_to, $subject, $body, $headers ) ){
  648.         $result = true;
  649.     }else{
  650.         $result = false;
  651.     }
  652.  
  653.     remove_filter( 'wp_mail_from', 'ova_wp_mail_from');
  654.     remove_filter( 'wp_mail_from_name', 'ova_wp_mail_from_name' );
  655.  
  656.     return $result;
  657. }
  658.  
  659.  
  660.  
  661. /* Select html Category Rental */
  662. function ovacrs_cat_rental( $selected, $required, $exclude_id ){
  663.     $args = array(
  664.         'show_option_all'    => '',
  665.         'show_option_none'   => esc_html__( 'All Categories', 'ova-crs' ),
  666.         'option_none_value'  => '',
  667.         'orderby'            => 'ID',
  668.         'order'              => 'ASC',
  669.         'show_count'         => 0,
  670.         'hide_empty'         => 0,
  671.         'child_of'           => 0,
  672.         'exclude'            => $exclude_id,
  673.         'include'            => '',
  674.         'echo'               => 0,
  675.         'selected'           => $selected,
  676.         'hierarchical'       => 1,
  677.         'name'               => 'cat',
  678.         'id'                 => '',
  679.         'class'              => 'postform '.$required,
  680.         'depth'              => 0,
  681.         'tab_index'          => 0,
  682.         'taxonomy'           => 'product_cat',
  683.         'hide_if_empty'      => false,
  684.         'value_field'        => 'slug',
  685.     );
  686.    
  687.    return wp_dropdown_categories($args);
  688. }
  689.  
  690.  
  691. function ovacrs_type_rental( $selected, $required, $exclude_id ){
  692.     $args = array(
  693.         'show_option_all'    => '',
  694.         'show_option_none'   => esc_html__( 'All Type', 'ova-crs' ),
  695.         'option_none_value'  => '',
  696.         'orderby'            => 'ID',
  697.         'order'              => 'ASC',
  698.         'show_count'         => 0,
  699.         'hide_empty'         => 0,
  700.         'child_of'           => 0,
  701.         'exclude'            => $exclude_id,
  702.         'include'            => '',
  703.         'echo'               => 0,
  704.         'selected'           => $selected,
  705.         'hierarchical'       => 1,
  706.         'name'               => 'product_type',
  707.         'id'                 => '',
  708.         'class'              => 'postform '.$required,
  709.         'depth'              => 0,
  710.         'tab_index'          => 0,
  711.         'taxonomy'           => 'type',
  712.         'hide_if_empty'      => false,
  713.         'value_field'        => 'slug',
  714.     );
  715.    
  716.    return wp_dropdown_categories($args);
  717. }
  718.  
  719.  
  720.  
  721. function ovacrs_pagination_theme($ovacrs_query = null) {
  722.    
  723.  
  724.     echo $ovacrs_query->max_num_pages.'x';
  725.  
  726.     /** Stop execution if there's only 1 page */
  727.     if($ovacrs_query != null){
  728.         if( $ovacrs_query->max_num_pages <= 1 )
  729.         return;
  730.     }else if( $wp_query->max_num_pages <= 1 )
  731.         return;
  732.  
  733.  
  734.  
  735.     $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1;
  736.  
  737.  
  738.    
  739.  
  740.     if($ovacrs_query!=null){
  741.         $max   = intval( $ovacrs_query->max_num_pages );
  742.     }else{
  743.         $max   = intval( $wp_query->max_num_pages );    
  744.     }
  745.    
  746.  
  747.     /** Add current page to the array */
  748.     if ( $paged >= 1 )
  749.         $links[] = $paged;
  750.  
  751.     /** Add the pages around the current page to the array */
  752.     if ( $paged >= 3 ) {
  753.         $links[] = $paged - 1;
  754.         $links[] = $paged - 2;
  755.     }
  756.  
  757.     if ( ( $paged + 2 ) <= $max ) {
  758.         $links[] = $paged + 2;
  759.         $links[] = $paged + 1;
  760.     }
  761.  
  762.  
  763.     echo '<nav class="woocommerce-pagination"><ul class="page-numbers">' . "\n";
  764.  
  765.     /** Previous Post Link */
  766.     if ( get_previous_posts_link() )
  767.         printf( '<li class="prev page-numbers">%s</li>' . "\n", get_previous_posts_link('<i class="arrow_carrot-left"></i>') );
  768.  
  769.     /** Link to first page, plus ellipses if necessary */
  770.     if ( ! in_array( 1, $links ) ) {
  771.         $class = 1 == $paged ? ' class="current"' : 'page-numbers';
  772.  
  773.         printf( '<li><a href="%s" %s>%s</a></li>' . "\n",  esc_url( get_pagenum_link( 1 ) ), $class, '1' );
  774.  
  775.         if ( ! in_array( 2, $links ) )
  776.             echo '<li>...</li>';
  777.     }
  778.  
  779.     /** Link to current page, plus 2 pages in either direction if necessary */
  780.     sort( $links );
  781.     foreach ( (array) $links as $link ) {
  782.         $class = $paged == $link ? ' class="current"' : '';
  783.         printf( '<li><a href="%s" %s>%s</a></li>' . "\n",  esc_url( get_pagenum_link( $link ) ), $class, $link );
  784.     }
  785.  
  786.     /** Link to last page, plus ellipses if necessary */
  787.     if ( ! in_array( $max, $links ) ) {
  788.         if ( ! in_array( $max - 1, $links ) )
  789.             echo '<li>...</li>' . "\n";
  790.  
  791.         $class = $paged == $max ? ' class="current"' : '';
  792.         printf( '<li><a href="%s" %s>%s</a></li>' . "\n",  esc_url( get_pagenum_link( $max ) ), $class, $max );
  793.     }
  794.  
  795.     /** Next Post Link */
  796.     if ( get_next_posts_link() )
  797.         printf( '<li class="next page-numbers">%s</li>' . "\n", get_next_posts_link('<i class="arrow_carrot-right"></i>') );
  798.  
  799.     echo '</ul></nav>' . "\n";
  800.  
  801. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement