diff --git a/assets/js/admin-order-bulk.js b/assets/js/admin-order-bulk.js index 22c3cb8b..2a5b83a4 100644 --- a/assets/js/admin-order-bulk.js +++ b/assets/js/admin-order-bulk.js @@ -66,6 +66,7 @@ post_form.find('#postnl-field-container').append(''); post_form.find('#postnl-field-container').append(''); post_form.find('#postnl-field-container').append(''); + post_form.find('#postnl-field-container').append(''); jQuery( this ).prop( 'disabled', true ); post_form.submit(); } ); diff --git a/assets/js/admin-order-single.js b/assets/js/admin-order-single.js index 53f795f2..4b34f987 100644 --- a/assets/js/admin-order-single.js +++ b/assets/js/admin-order-single.js @@ -242,5 +242,21 @@ postnl_order_single.init(); + if ( $( 'div.pickup-points-info' ).length ) { + $( '#postnl_id_check, #postnl_insured_shipping' ).on( 'change', function() { + // Get the ID of the current checkbox + var currentId = $(this).attr( 'id' ); + + // Uncheck the other checkbox + if ( $(this).is( ':checked' ) ) { + if ( currentId === 'postnl_id_check' ) { + $( '#postnl_insured_shipping' ).prop( 'checked', false ); + } else { + $( '#postnl_id_check' ).prop( 'checked', false ); + } + } + }); + } + window.postnl_order_single_refresh = postnl_order_single.refresh_items; } )( jQuery ); diff --git a/src/Helper/Mapping.php b/src/Helper/Mapping.php index c8f882f8..f9eb1825 100644 --- a/src/Helper/Mapping.php +++ b/src/Helper/Mapping.php @@ -135,6 +135,16 @@ public static function products_data() { ), ), ), + array( + 'combination' => array( 'id_check', 'insured_shipping' ), + 'code' => '3443', + 'options' => array( + array( + 'characteristic' => '002', + 'option' => '014', + ), + ), + ), ), 'pickup_points' => array( array( @@ -147,6 +157,16 @@ public static function products_data() { 'code' => '3534', 'options' => array(), ), + array( + 'combination' => array( 'id_check' ), + 'code' => '3571', + 'options' => array( + array( + 'characteristic' => '002', + 'option' => '014', + ), + ), + ), ) ), 'BE' => array( @@ -639,6 +659,8 @@ public static function shipping_return_labels_options() { '3089', '3533', '3534', + '3443', + '3571', ), 'options' => array( array( @@ -662,6 +684,8 @@ public static function shipping_return_labels_options() { '3089', '3533', '3534', + '3443', + '3571', ), 'options' => array( array( diff --git a/src/Order/Base.php b/src/Order/Base.php index 7e167f95..85c66d3e 100644 --- a/src/Order/Base.php +++ b/src/Order/Base.php @@ -122,6 +122,12 @@ public function get_shipping_options( $order ) { // Get from the plugin settings $delivery_zone = $this->get_shipping_zone( $order ); + $frontend_data = $this->get_frontend_data( $order->get_id() ); + + if ( ! empty( $frontend_data['dropoff_points'] ) ) { + $delivery_zone = 'PICKUP'; + } + if ( 'NL' === $delivery_zone && Utils::is_eligible_auto_letterbox( $order ) ) { return array( 'letterbox' => 'yes' ); } diff --git a/src/Order/Bulk.php b/src/Order/Bulk.php index b2c17076..c0dbda4b 100644 --- a/src/Order/Bulk.php +++ b/src/Order/Bulk.php @@ -130,8 +130,7 @@ public function bulk_action_create_label( $redirect, $doaction, $object_ids ) { * @return string */ public function bulk_action_change_shipping_options( $redirect, $doaction, $object_ids ) { - - if ( 'postnl-change-shipping-options' !== $doaction ) { + if ( 'postnl-change-shipping-options' !== $doaction || empty( $object_ids ) ) { return $redirect; } @@ -142,32 +141,38 @@ public function bulk_action_change_shipping_options( $redirect, $doaction, $obje $selected_shipping_options = $this->prepare_default_options( $_REQUEST ); $zone = strtoupper( sanitize_text_field( $_REQUEST['postnl_shipping_zone'] ) ); - if ( ! empty( $object_ids ) ) { - foreach ( $object_ids as $order_id ) { - $order = wc_get_order( $order_id ); - $have_label_file = $this->have_label_file( $order ); - $match_shipping_zones = $zone === $this->get_shipping_zone( $order ); - - if ( $have_label_file ) { - $array_messages[] = array( - 'message' => sprintf( esc_html__( 'Order #%1$d already has a label.', 'postnl-for-woocommerce' ), $order_id ), - 'type' => 'error', - ); - } + foreach ( $object_ids as $order_id ) { + $order = wc_get_order( $order_id ); + $have_label_file = $this->have_label_file( $order ); + $match_shipping_zones = $zone === $this->get_shipping_zone( $order ); + $match_pickup_zone = 'PICKUP' === $zone && 'NL' === $this->get_shipping_zone( $order ); + if ( $have_label_file ) { + $array_messages[] = array( + 'message' => sprintf( esc_html__( 'Order #%1$d already has a label.', 'postnl-for-woocommerce' ), $order_id ), + 'type' => 'error', + ); + + continue; + } - if ( ! $match_shipping_zones ) { - $array_messages[] = array( - 'message' => sprintf( esc_html__( 'Order #%1$d is from another shipping zone.', 'postnl-for-woocommerce' ), $order_id ), - 'type' => 'error', - ); - } + if ( ! $match_shipping_zones && ! $match_pickup_zone ) { + $array_messages[] = array( + 'message' => sprintf( esc_html__( 'Order #%1$d is from another shipping zone.', 'postnl-for-woocommerce' ), $order_id ), + 'type' => 'error', + ); - if ( ! $have_label_file && $match_shipping_zones ) { - $order->delete_meta_data( $this->meta_name ); - $order->update_meta_data( $this->meta_name, array( 'backend' => $selected_shipping_options ) ); - $order->save(); - } + continue; } + + $meta = $order->get_meta( $this->meta_name ); + + if ( ! is_array( $meta ) ) { + $meta = array(); + } + + $meta['backend'] = $selected_shipping_options; + $order->update_meta_data( $this->meta_name, $meta ); + $order->save(); } update_option( $this->bulk_option_text_name, $array_messages ); @@ -487,10 +492,11 @@ protected function change_shipping_options_fields() { 'value' => 'nl', 'container' => true, 'options' => array( - 'nl' => __( 'Domestic', 'postnl-for-woocommerce' ), - 'be' => __( 'Belgium', 'postnl-for-woocommerce' ), - 'eu' => __( 'EU Parcel', 'postnl-for-woocommerce' ), - 'row' => __( 'Non-EU Shipment', 'postnl-for-woocommerce' ), + 'nl' => __( 'Domestic', 'postnl-for-woocommerce' ), + 'be' => __( 'Belgium', 'postnl-for-woocommerce' ), + 'eu' => __( 'EU Parcel', 'postnl-for-woocommerce' ), + 'row' => __( 'Non-EU Shipment', 'postnl-for-woocommerce' ), + 'pickup' => __( 'Pick-up at PostNL', 'postnl-for-woocommerce' ), ), ), array( @@ -529,6 +535,15 @@ protected function change_shipping_options_fields() { 'value' => $this->settings->get_country_option( 'default_shipping_options_' . 'row' ), 'options' => $this->get_available_shipping_options_per_zone( 'row' ), ), + array( + 'id' => $this->prefix . 'default_shipping_options_pickup', + 'type' => 'select', + 'label' => __( 'Shipping options for Pick-up at PostNL', 'postnl-for-woocommerce' ), + 'wrapper_class' => 'conditional pickup', + 'container' => true, + 'value' => $this->settings->get_country_option( 'default_shipping_options_' . 'pickup' ), + 'options' => $this->get_available_shipping_options_per_zone( 'pickup' ), + ), ); } diff --git a/src/Shipping_Method/Settings.php b/src/Shipping_Method/Settings.php index c994c0e2..8cf58c10 100644 --- a/src/Shipping_Method/Settings.php +++ b/src/Shipping_Method/Settings.php @@ -541,6 +541,7 @@ public function get_setting_fields() { 'options' => array( 'standard_shipment' => __( 'Standard shipment', 'postnl-for-woocommerce' ), 'id_check' => __( 'ID Check', 'postnl-for-woocommerce' ), + 'id_check|insured_shipping' => __( 'ID Check + Insured Shipping', 'postnl-for-woocommerce' ), // 'insured_shipping' => __( 'Insured Shipping', 'postnl-for-woocommerce' ), 'return_no_answer' => __( 'Return if no answer', 'postnl-for-woocommerce' ), 'signature_on_delivery' => __( 'Signature on Delivery', 'postnl-for-woocommerce' ), @@ -606,6 +607,17 @@ public function get_setting_fields() { 'packets|track_and_trace|insured_shipping' => __( 'Packets + Track & Trace + Insured', 'postnl-for-woocommerce' ), ), ), + 'default_shipping_options_pickup' => array( + 'title' => __( 'Default Shipping Pickup', 'postnl-for-woocommerce' ), + 'type' => 'select', + 'description' => __( 'Shipping options Pickup.', 'postnl-for-woocommerce' ), + 'default' => 'id_check', + 'for_country' => array( 'NL' ), + 'options' => array( + 'id_check' => __( 'ID Check', 'postnl-for-woocommerce' ), + 'insured_shipping' => __( 'Insured Shipping', 'postnl-for-woocommerce' ), + ), + ), 'auto_complete_order' => array( 'title' => esc_html__( 'Automatically change order status to Completed', 'postnl-for-woocommerce' ), 'type' => 'checkbox',