css
8 months ago
js
8 months ago
class-css.php
8 months ago
class-date.php
8 months ago
class-delivery-type.php
8 months ago
class-display-field.php
8 months ago
class-extra-message.php
8 months ago
class-js.php
8 months ago
class-main.php
8 months ago
class-myaccount.php
8 months ago
class-order.php
8 months ago
class-pickup-location.php
8 months ago
class-shipping-method.php
8 months ago
class-time-range.php
8 months ago
class-time-slot.php
8 months ago
class-time.php
8 months ago
class-validate.php
8 months ago
class-woo-app.php
8 months ago
class-shipping-method.php
64 lines
| 1 | <?php |
| 2 | class pisol_dtt_shipping_method{ |
| 3 | |
| 4 | function __construct(){ |
| 5 | |
| 6 | add_filter( 'woocommerce_product_needs_shipping',array(__CLASS__, 'productNeedsShipping'), PHP_INT_MAX); |
| 7 | add_filter( 'woocommerce_cart_needs_shipping_address', array(__CLASS__, 'productNeedsShipping'), PHP_INT_MAX); |
| 8 | add_filter( 'woocommerce_customer_taxable_address', array($this, 'shopBasedTaxableAddress')); |
| 9 | |
| 10 | /** |
| 11 | * This sill disable the Woocommerce given option of switching between pickup and delivery on checkout page |
| 12 | */ |
| 13 | add_filter( 'option_woocommerce_pickup_location_settings', array(__CLASS__, 'disableBlockPickupDeliverySwitcher'), 20); |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * When pickup is selected we do the Tax calculation based on the shop |
| 18 | * base address |
| 19 | */ |
| 20 | function shopBasedTaxableAddress($location){ |
| 21 | if(self::disabled()) return $location; |
| 22 | |
| 23 | $type = pi_dtt_delivery_type::getType(); |
| 24 | |
| 25 | if($type != 'pickup') return $location; |
| 26 | |
| 27 | $country = WC()->countries->get_base_country(); |
| 28 | $state = WC()->countries->get_base_state(); |
| 29 | $postcode = WC()->countries->get_base_postcode(); |
| 30 | $city = WC()->countries->get_base_city(); |
| 31 | return array( $country, $state, $postcode, $city ); |
| 32 | } |
| 33 | |
| 34 | static function productNeedsShipping($val){ |
| 35 | |
| 36 | if(self::disabled()) return $val; |
| 37 | |
| 38 | $type = pi_dtt_delivery_type::getType(); |
| 39 | if($type == 'pickup'){ |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | return $val; |
| 44 | } |
| 45 | |
| 46 | static function disabled(){ |
| 47 | return apply_filters('pisol_disable_dtt_completely',false); |
| 48 | } |
| 49 | |
| 50 | static function disableBlockPickupDeliverySwitcher( $value ) { |
| 51 | if ( is_admin() ) { |
| 52 | return $value; |
| 53 | } |
| 54 | |
| 55 | // Force-disable pickup dynamically |
| 56 | if(is_array($value)){ |
| 57 | $value['enabled'] = 'no'; |
| 58 | } |
| 59 | |
| 60 | return $value; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | new pisol_dtt_shipping_method(); |