Ejemplo n.º 1
0
 /**
  * Add resources field
  */
 private function resources_field()
 {
     // Resources field
     if ('yes' == $this->product->wc_booking_has_resources && 'customer' == $this->product->wc_booking_resources_assignment) {
         $resources = $this->product->get_resources();
         $resource_options = array();
         $data = array();
         foreach ($resources as $resource) {
             $additional_cost = '';
             $cost_plus_base = $resource->get_base_cost() + $resource->get_block_cost() + $this->product->wc_booking_base_cost + $this->product->wc_booking_cost;
             $additional_cost = array();
             if ($resource->get_base_cost() && $this->product->get_base_cost() < $cost_plus_base) {
                 $additional_cost[] = '+' . wc_price($cost_plus_base - $this->product->get_base_cost());
             }
             if ($resource->get_block_cost()) {
                 $additional_cost[] = sprintf(__('%s per additional block', 'woocommerce-bookings'), wc_price($resource->get_block_cost()));
             }
             if ($additional_cost) {
                 $additional_cost_string = ' (' . implode(', +', $additional_cost) . ')';
             } else {
                 $additional_cost_string = '';
             }
             $resource_options[$resource->ID] = $resource->post_title . $additional_cost_string;
         }
         $this->add_field(array('type' => 'select', 'name' => 'resource', 'label' => $this->product->wc_booking_resouce_label ? $this->product->wc_booking_resouce_label : __('Type', 'woocommerce-bookings'), 'options' => $resource_options));
     }
 }
 /**
  * Add resources field
  */
 private function resources_field()
 {
     // Resources field
     if ('yes' == $this->product->wc_booking_has_resources && 'customer' == $this->product->wc_booking_resources_assignment) {
         $resources = $this->product->get_resources();
         $resource_options = array();
         $data = array();
         foreach ($resources as $resource) {
             $additional_cost = '';
             $cost_plus_base = $resource->get_base_cost() + $resource->get_block_cost() + $this->product->wc_booking_base_cost + $this->product->wc_booking_cost;
             $additional_cost = array();
             if ($resource->get_base_cost() && $this->product->get_base_cost() < $cost_plus_base) {
                 $additional_cost[] = '+' . wc_price($cost_plus_base - $this->product->get_base_cost());
             }
             if ($resource->get_block_cost()) {
                 switch ($this->product->get_duration_unit()) {
                     case 'month':
                         $additional_cost[] = sprintf(__('+%s per month', 'woocommerce-bookings'), wc_price($resource->get_block_cost() + $this->product->wc_booking_base_cost));
                         break;
                     case 'day':
                         $additional_cost[] = sprintf(__('+%s per day', 'woocommerce-bookings'), wc_price($resource->get_block_cost() + $this->product->wc_booking_base_cost));
                         break;
                     default:
                         $additional_cost[] = sprintf(__('+%s per block', 'woocommerce-bookings'), wc_price($resource->get_block_cost() + $this->product->wc_booking_base_cost));
                         break;
                 }
             }
             if ($additional_cost) {
                 $additional_cost_string = ' (' . implode(', +', $additional_cost) . ')';
             } else {
                 $additional_cost_string = '';
             }
             $resource_options[$resource->ID] = $resource->post_title . apply_filters('woocommerce_bookings_resource_additional_cost_string', $additional_cost_string, $resource);
         }
         $this->add_field(array('type' => 'select', 'name' => 'resource', 'label' => $this->product->wc_booking_resouce_label ? $this->product->wc_booking_resouce_label : __('Type', 'woocommerce-bookings'), 'class' => array('wc_booking_field_' . sanitize_title($this->product->wc_booking_resouce_label)), 'options' => $resource_options));
     }
 }