ublic function force_shipping_enabled( $enabled ) { if ( CartCheckoutUtils::is_checkout_block_default() && $this->local_pickup_enabled ) { return true; } return $enabled; } /** * Inject collection details onto the order received page. * * @param string $return Return value. * @param \WC_Order $order Order object. * @return string */ public function show_local_pickup_details( $return, $order ) { // Confirm order is valid before proceeding further. if ( ! $order instanceof \WC_Order ) { return $return; } $shipping_method_ids = ArrayUtil::select( $order->get_shipping_methods(), 'get_method_id', ArrayUtil::SELECT_BY_OBJECT_METHOD ); $shipping_method_id = current( $shipping_method_ids ); // Ensure order used pickup location method, otherwise bail. if ( 'pickup_location' !== $shipping_method_id ) { return $return; } $shipping_method = current( $order->get_shipping_methods() ); $details = $shipping_method->get_meta( 'pickup_details' ); $location = $shipping_method->get_meta( 'pickup_location' ); $address = $shipping_method->get_meta( 'pickup_address' ); return sprintf( // Translators: %s location name. __( 'Pickup from %s:', 'woocommerce' ), $location ) . '
' . str_replace( ',', ',
', $address ) . '

' . $details; } /** * If the Checkout block Remove shipping settings from WC Core's admin panels that are now block settings. * * @param array $settings The default WC shipping settings. * @return array|mixed The filtered settings with relevant items removed. */ public function remove_shipping_settings( $settings ) { // Do not add the shipping calculator setting if the Cart block is not used on the WC cart page. if ( CartCheckoutUtils::is_cart_block_default() ) { // Ensure the 'Calculations' title is added to the `woocommerce_shipping_cost_requires_address` options // group, since it is attached to the `woocommerce_enable_shipping_calc` option that gets removed if the // Cart block is in use. $calculations_title = ''; // Get Calculations title so we can add it to 'Hide shipping costs until an address is entered' option. foreach ( $settings as $setting ) { if ( 'woocommerce_enable_shipping_calc' === $setting['id'] ) { $calculations_title = $setting['title']; break; } } // Add Calculations title to 'Hide shipping costs until an address is entered' option. foreach ( $settings as $index => $setting ) { if ( 'woocommerce_shipping_cost_requires_address' === $setting['id'] ) { $settings[ $index ]['title'] = $calculations_title; $settings[ $index ]['checkboxgroup'] = 'start'; break; } } $settings = array_filter( $settings, function( $setting ) { return ! in_array( $setting['id'], array( 'woocommerce_enable_shipping_calc', ), true ); } ); } if ( CartCheckoutUtils::is_checkout_block_default() && $this->local_pickup_enabled ) { foreach ( $settings as $index => $setting ) { if ( 'woocommerce_shipping_cost_requires_address' === $setting['id'] ) { $settings[ $index ]['desc'] .= ' (' . __( 'Not available when using WooCommerce Blocks Local Pickup', 'woocommerce' ) . ')'; $settings[ $index ]['disabled'] = true; $settings[ $index ]['value'] = 'no'; break; } } } return $settings; } /** * Register Local Pickup settings for rest api. */ public function register_settings() { register_setting( 'options', 'woocommerce_pickup_location_settings', [ 'type' => 'object', 'description' => 'WooCommerce Local Pickup Method Settings', 'default' => [], 'show_in_rest' => [ 'name' => 'pickup_location_settings', 'schema' => [ 'type' => 'object', 'properties' => array( 'enabled' => [ 'description' => __( 'If enabled, this method will appear on the block based checkout.', 'woocommerce' ), 'type' => 'string', 'enum' => [ 'yes', 'no' ], ], 'title' => [ 'description' => __( 'This controls the title which the user sees during checkout.', 'woocommerce' ), 'type' => 'string', ], 'tax_status' => [ 'description' => __( 'If a cost is defined, this controls if taxes are applied to that cost.', 'woocommerce' ), 'type' => 'string', 'enum' => [ 'taxable', 'none' ], ], 'cost' => [ 'description' => __( 'Optional cost to charge for local pickup.', 'woocommerce' ), 'type' => 'string', ], ), ], ], ] ); register_setting( 'options', 'pickup_location_pickup_locations', [ 'type' => 'array', 'description' => 'WooCommerce Local Pickup Locations', 'default' => [], 'show_in_rest' => [ 'name' => 'pickup_locations', 'schema' => [ 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => array( 'name' => [ 'type' => 'string', ], 'address' => [ 'type' => 'object', 'properties' => array( 'address_1' => [ 'type' => 'string', ], 'city' => [ 'type' => 'string', ], 'state' => [ 'type' => 'string', ], 'postcode' => [ 'type' => 'string', ], 'country' => [ 'type' => 'string', ], ), ], 'details' => [ 'type' => 'string', ], 'enabled' => [ 'type' => 'boolean', ], ), ], ], ], ] ); } /** * Hydrate client settings */ public function hydrate_client_settings() { $locations = get_option( 'pickup_location_pickup_locations', [] ); $formatted_pickup_locations = []; foreach ( $locations as $location ) { $formatted_pickup_locations[] = [ 'name' => $location['name'], 'address' => $location['address'], 'details' => $location['details'], 'enabled' => wc_string_to_bool( $location['enabled'] ), ]; } $has_legacy_pickup = false; // Get all shipping zones. $shipping_zones = \WC_Shipping_Zones::get_zones( 'admin' ); $international_shipping_zone = new \WC_Shipping_Zone( 0 ); // Loop through each shipping zone. foreach ( $shipping_zones as $shipping_zone ) { // Get all registered rates for this shipping zone. $shipping_methods = $shipping_zone['shipping_methods']; // Loop through each registered rate. foreach ( $shipping_methods as $shipping_method ) { if ( 'local_pickup' === $shipping_method->id && 'yes' === $shipping_method->enabled ) { $has_legacy_pickup = true; break 2; } } } foreach ( $international_shipping_zone->get_shipping_methods( true ) as $shipping_method ) { if ( 'local_pickup' === $shipping_method->id ) { $has_legacy_pickup = true; break; } } $settings = array( 'pickupLocationSettings' => get_option( 'woocommerce_pickup_location_settings', [] ), 'pickupLocations' => $formatted_pickup_locations, 'readonlySettings' => array( 'hasLegacyPickup' => $has_legacy_pickup, 'storeCountry' => WC()->countries->get_base_country(), 'storeState' => WC()->countries->get_base_state(), ), ); wp_add_inline_script( 'wc-shipping-method-pickup-location', sprintf( 'var hydratedScreenSettings = %s;', wp_json_encode( $settings ) ), 'before' ); } /** * Load admin scripts. */ public function admin_scripts() { $this->asset_api->register_script( 'wc-shipping-method-pickup-location', 'build/wc-shipping-method-pickup-location.js', [], true ); } /** * Registers the Local Pickup shipping method used by the Checkout Block. */ public function register_local_pickup() { if ( CartCheckoutUtils::is_checkout_block_default() ) { wc()->shipping->register_shipping_method( new PickupLocation() ); } } /** * Declares the Pickup Location shipping method as a Local Pickup method for WooCommerce. * * @param array $methods Shipping method ids. * @return array */ public function register_local_pickup_method( $methods ) { $methods[] = 'pickup_location'; return $methods; } /** * Hides the shipping address on the order confirmation page when local pickup is selected. * * @param array $pickup_methods Method ids. * @return array */ public function hide_shipping_address_for_local_pickup( $pickup_methods ) { return array_merge( $pickup_methods, LocalPickupUtils::get_local_pickup_method_ids() ); } /** * Everytime we save or update local pickup settings, we flush the shipping * transient group. * * @param array $settings The setting array we're saving. * @return array $settings The setting array we're saving. */ public function flush_cache( $settings ) { \WC_Cache_Helper::get_transient_version( 'shipping', true ); return $settings; } /** * Filter the location used for taxes based on the chosen pickup location. * * @param array $address Location args. * @return array */ public function filter_taxable_address( $address ) { if ( null === WC()->session ) { return $address; } // We only need to select from the first package, since pickup_location only supports a single package. $chosen_method = current( WC()->session->get( 'chosen_shipping_methods', array() ) ) ?? ''; $chosen_method_id = explode( ':', $chosen_method )[0]; $chosen_method_instance = explode( ':', $chosen_method )[1] ?? 0; // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment if ( $chosen_method_id && true === apply_filters( 'woocommerce_apply_base_tax_for_local_pickup', true ) && in_array( $chosen_method_id, LocalPickupUtils::get_local_pickup_method_ids(), true ) ) { $pickup_locations = get_option( 'pickup_location_pickup_locations', [] ); $pickup_location = $pickup_locations[ $chosen_method_instance ] ?? []; if ( isset( $pickup_location['address'], $pickup_location['address']['country'] ) && ! empty( $pickup_location['address']['country'] ) ) { $address = array( $pickup_locations[ $chosen_method_instance ]['address']['country'], $pickup_locations[ $chosen_method_instance ]['address']['state'], $pickup_locations[ $chosen_method_instance ]['address']['postcode'], $pickup_locations[ $chosen_method_instance ]['address']['city'], ); } } return $address; } /** * Local Pickup requires all packages to support local pickup. This is because the entire order must be picked up * so that all packages get the same tax rates applied during checkout. * * If a shipping package does not support local pickup (e.g. if disabled by an extension), this filters the option * out for all packages. This will in turn disable the "pickup" toggle in Block Checkout. * * @param array $packages Array of shipping packages. * @return array */ public function filter_shipping_packages( $packages ) { // Check all packages for an instance of a collectable shipping method. $valid_packages = array_filter( $packages, function( $package ) { $shipping_method_ids = ArrayUtil::select( $package['rates'] ?? [], 'get_method_id', ArrayUtil::SELECT_BY_OBJECT_METHOD ); return ! empty( array_intersect( LocalPickupUtils::get_local_pickup_method_ids(), $shipping_method_ids ) ); } ); // Remove pickup location from rates arrays. if ( count( $valid_packages ) !== count( $packages ) ) { $packages = array_map( function( $package ) { if ( ! is_array( $package['rates'] ) ) { $package['rates'] = []; return $package; } $package['rates'] = array_filter( $package['rates'], function( $rate ) { return ! in_array( $rate->get_method_id(), LocalPickupUtils::get_local_pickup_method_ids(), true ); } ); return $package; }, $packages ); } return $packages; } }
Fatal error: Uncaught Error: Class "Automattic\WooCommerce\Blocks\Shipping\ShippingController" not found in /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Domain/Bootstrap.php:378 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Domain\Bootstrap->Automattic\WooCommerce\Blocks\Domain\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #1 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #2 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #3 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Domain/Bootstrap.php(139): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #4 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Domain/Bootstrap.php(75): Automattic\WooCommerce\Blocks\Domain\Bootstrap->init() #5 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Package.php(125): Automattic\WooCommerce\Blocks\Domain\Bootstrap->__construct(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #6 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/AbstractDependencyType.php(42): Automattic\WooCommerce\Blocks\Package::Automattic\WooCommerce\Blocks\{closure}(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #7 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/SharedType.php(28): Automattic\WooCommerce\Blocks\Registry\AbstractDependencyType->resolve_value(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #8 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Registry/Container.php(96): Automattic\WooCommerce\Blocks\Registry\SharedType->get(Object(Automattic\WooCommerce\Blocks\Registry\Container)) #9 /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Package.php(44): Automattic\WooCommerce\Blocks\Registry\Container->get('Automattic\\WooC...') #10 [internal function]: Automattic\WooCommerce\Blocks\Package::init() #11 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(71): call_user_func(Array) #12 /htdocs/wp-content/plugins/woocommerce/src/Packages.php(44): Automattic\WooCommerce\Packages::load_packages() #13 /htdocs/wp-includes/class-wp-hook.php(310): Automattic\WooCommerce\Packages::on_init('') #14 /htdocs/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #15 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #16 /htdocs/wp-settings.php(495): do_action('plugins_loaded') #17 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #18 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #19 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #20 /htdocs/index.php(17): require('/htdocs/wp-blog...') #21 {main} thrown in /htdocs/wp-content/plugins/woocommerce/packages/woocommerce-blocks/src/Domain/Bootstrap.php on line 378