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