css
1 year ago
js
1 year ago
class-css.php
1 year ago
class-date.php
1 year ago
class-delivery-type.php
1 year ago
class-display-field.php
1 year ago
class-js.php
1 year ago
class-main.php
1 year ago
class-myaccount.php
1 year ago
class-order.php
1 year ago
class-pickup-location.php
1 year ago
class-shipping-method.php
1 year ago
class-time-range.php
1 year ago
class-time-slot.php
1 year ago
class-time.php
1 year ago
class-validate.php
1 year ago
class-woo-app.php
1 year ago
class-delivery-type.php
108 lines
| 1 | <?php |
| 2 | if ( ! defined( 'WPINC' ) ) { |
| 3 | die; |
| 4 | } |
| 5 | class pi_dtt_delivery_type{ |
| 6 | |
| 7 | public $default_type; |
| 8 | |
| 9 | function __construct(){ |
| 10 | $this->default_type = pisol_dtt_get_setting('pi_default_type', 'delivery'); |
| 11 | } |
| 12 | |
| 13 | static function getType(){ |
| 14 | $obj = new self(); |
| 15 | $type = $obj->getDeliveryType(); |
| 16 | return $type; |
| 17 | } |
| 18 | |
| 19 | function availableDeliveryType(){ |
| 20 | $aloud_types = pisol_dtt_get_setting('pi_type', "Both"); |
| 21 | if($aloud_types == "Both"){ |
| 22 | return 'both'; |
| 23 | } |
| 24 | |
| 25 | if($aloud_types == "Pickup"){ |
| 26 | return 'pickup'; |
| 27 | } |
| 28 | |
| 29 | if($aloud_types == "Delivery"){ |
| 30 | return 'delivery'; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | function getDeliveryType(){ |
| 35 | $available_type = $this->availableDeliveryType(); |
| 36 | |
| 37 | if($this->checkDeliveryTypeSetInSession( $available_type )){ |
| 38 | $type = WC()->session->get( 'pi_delivery_type', false); |
| 39 | return $type; |
| 40 | } |
| 41 | |
| 42 | if($available_type != "both"){ |
| 43 | $this->setDeliveryType($available_type); |
| 44 | return $available_type; |
| 45 | } |
| 46 | |
| 47 | return $this->setDeliveryType($this->default_type); |
| 48 | } |
| 49 | |
| 50 | function setDeliveryType($type){ |
| 51 | if($this->checkSession()){ |
| 52 | WC()->session->set("pi_delivery_type", $type); |
| 53 | return WC()->session->get( 'pi_delivery_type', false); |
| 54 | } |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | function checkDeliveryTypeSetInSession($available_type){ |
| 59 | if($this->checkSession()){ |
| 60 | $type = WC()->session->get( 'pi_delivery_type', false); |
| 61 | if($available_type == 'both' && ($type == 'pickup' || $type == 'delivery')){ |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | if($available_type == 'pickup' && ($type == 'pickup')){ |
| 66 | return true; |
| 67 | } |
| 68 | |
| 69 | if($available_type == 'delivery' && ($type == 'delivery')){ |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | |
| 74 | if($this->allowedCustomType($type)){ |
| 75 | return true; |
| 76 | } |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | function allowedCustomType($type){ |
| 82 | $custom_type = apply_filters('pisol_dtt_custom_delivery_type',""); |
| 83 | if($custom_type == "") return false; |
| 84 | |
| 85 | if(is_array($custom_type)){ |
| 86 | if(in_array($type, $custom_type)){ |
| 87 | return true; |
| 88 | }else{ |
| 89 | return false; |
| 90 | } |
| 91 | }else{ |
| 92 | if($type == $custom_type){ |
| 93 | return true; |
| 94 | }else{ |
| 95 | return false; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | } |
| 100 | |
| 101 | function checkSession(){ |
| 102 | if(function_exists('WC') && isset(WC()->session)){ |
| 103 | return true; |
| 104 | } |
| 105 | return false; |
| 106 | } |
| 107 | |
| 108 | } |