diff --git a/postnl-for-woocommerce.php b/postnl-for-woocommerce.php index 27dfb91b..1563b610 100644 --- a/postnl-for-woocommerce.php +++ b/postnl-for-woocommerce.php @@ -5,8 +5,11 @@ * Description: With this plug-in you can easily confirm your PostNL shipments and print shipping labels in no time. In addition, your customers are more in control because they choose where and when they receive their order. * Author: PostNL * Author URI: https://postnl.post/ + * License: GPLv2 or later + * License URI: https://www.gnu.org/licenses/gpl-2.0.html * Version: 5.6.2 - * Tested up to: 6.6 + * Tested up to: 6.7 + * Requires Plugins: woocommerce * WC requires at least: 4.0 * WC tested up to: 9.3 * diff --git a/readme.txt b/readme.txt index 01022335..f6616d80 100644 --- a/readme.txt +++ b/readme.txt @@ -3,10 +3,10 @@ Contributors: PostNL, shadim, abdalsalaam Tags: woocommerce, export, delivery, packages, PostNL, Shipping Requires at least: 4.6 Requires PHP: 5.6 -Tested up to: 6.6 +Tested up to: 6.7 Stable tag: 5.6.2 WC requires at least: 4.0 -WC tested up to: 9.3 +WC tested up to: 9.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html diff --git a/src/Emails/WC_Email_Smart_Return.php b/src/Emails/WC_Email_Smart_Return.php index 305d9c77..d74feeba 100644 --- a/src/Emails/WC_Email_Smart_Return.php +++ b/src/Emails/WC_Email_Smart_Return.php @@ -53,7 +53,7 @@ public function __construct() { * @since 3.1.0 */ public function get_default_subject() { - return __( '[{site_title}]: PostNL Smart Returns', 'woocommerce' ); + return __( '[{site_title}]: PostNL Smart Returns', 'postnl-for-woocommerce' ); } /** @@ -63,7 +63,7 @@ public function get_default_subject() { * @since 3.1.0 */ public function get_default_heading() { - return __( 'PostNL Smart Returns', 'woocommerce' ); + return __( 'PostNL Smart Returns', 'postnl-for-woocommerce' ); } /** diff --git a/src/Frontend/Base.php b/src/Frontend/Base.php index 94fac7e9..2d13a0c3 100644 --- a/src/Frontend/Base.php +++ b/src/Frontend/Base.php @@ -240,7 +240,7 @@ public function validate_posted_data( $data ) { $nonce_value = wc_get_var( $_REQUEST['woocommerce-process-checkout-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) ); // phpcs:ignore $expiry_message = sprintf( /* translators: %s: shop cart url */ - __( 'Sorry, your session has expired. Return to shop', 'woocommerce' ), + __( 'Sorry, your session has expired. Return to shop', 'postnl-for-woocommerce' ), esc_url( wc_get_page_permalink( 'shop' ) ) ); @@ -492,7 +492,7 @@ public function save_letterbox_data( $order_id, $posted_data ) { return; } - $eligible_for_letterbox = Utils::is_eligible_auto_letterbox( $order ); + $eligible_for_letterbox = Utils::is_order_eligible_auto_letterbox( $order ); if ( $eligible_for_letterbox ) { $order->update_meta_data( $this->letterbox_meta_name, 1 ); diff --git a/src/Frontend/Container.php b/src/Frontend/Container.php index 702a08f8..fdbc9392 100644 --- a/src/Frontend/Container.php +++ b/src/Frontend/Container.php @@ -133,7 +133,7 @@ public function get_checkout_data( $post_data ) { $item_info = new Checkout\Item_Info( $post_data ); $api_call = new Checkout\Client( $item_info ); $response = $api_call->send_request(); - $letterbox = Utils::is_eligible_auto_letterbox( \WC()->cart ); + $letterbox = Utils::is_cart_eligible_auto_letterbox( \WC()->cart ); return array( 'response' => $response, diff --git a/src/Order/Base.php b/src/Order/Base.php index 7e167f95..b578ce89 100644 --- a/src/Order/Base.php +++ b/src/Order/Base.php @@ -122,7 +122,7 @@ public function get_shipping_options( $order ) { // Get from the plugin settings $delivery_zone = $this->get_shipping_zone( $order ); - if ( 'NL' === $delivery_zone && Utils::is_eligible_auto_letterbox( $order ) ) { + if ( 'NL' === $delivery_zone && Utils::is_order_eligible_auto_letterbox( $order ) ) { return array( 'letterbox' => 'yes' ); } diff --git a/src/Order/Bulk.php b/src/Order/Bulk.php index b2c17076..1c039a76 100644 --- a/src/Order/Bulk.php +++ b/src/Order/Bulk.php @@ -150,6 +150,7 @@ public function bulk_action_change_shipping_options( $redirect, $doaction, $obje if ( $have_label_file ) { $array_messages[] = array( + // Translators: %1$d is the order ID. 'message' => sprintf( esc_html__( 'Order #%1$d already has a label.', 'postnl-for-woocommerce' ), $order_id ), 'type' => 'error', ); @@ -157,6 +158,7 @@ public function bulk_action_change_shipping_options( $redirect, $doaction, $obje if ( ! $match_shipping_zones ) { $array_messages[] = array( + // Translators: %1$d is the order ID. 'message' => sprintf( esc_html__( 'Order #%1$d is from another shipping zone.', 'postnl-for-woocommerce' ), $order_id ), 'type' => 'error', ); @@ -666,6 +668,7 @@ public function generate_label_and_notes( $order_id, $post_data ) { $order->add_order_note( $tracking_note, $customer_note ); $label_link = esc_url( $this->get_download_label_url( $order_id ) ); $result['message'] = array( + // Translators: %1$s is the order ID, %2$s is the link to download the file, %3$s is the closing link tag. 'message' => sprintf( esc_html__( '#%1$s : PostNL label has been created - %2$sdownload file%3$s', 'postnl-for-woocommerce' ), $order_id, '', '' ), 'type' => 'success', diff --git a/src/Order/OrdersList.php b/src/Order/OrdersList.php index 4091b7c1..3850b874 100644 --- a/src/Order/OrdersList.php +++ b/src/Order/OrdersList.php @@ -143,7 +143,7 @@ public function add_order_delivery_date_column_content( $column, $order_id ) { return; } - if ( Utils::is_eligible_auto_letterbox( $order ) ) { + if ( Utils::is_order_eligible_auto_letterbox( $order ) ) { esc_html_e( 'As soon as possible', 'postnl-for-woocommerce' ); return; } @@ -271,7 +271,7 @@ public function add_eligible_auto_letterbox_column_header( $columns ) { */ public function add_eligible_auto_letterbox_column_content( $column, $order_id ) { if ( 'postnl_eligible_auto_letterbox' === $column ) { - if ( Utils::is_eligible_auto_letterbox( $order_id ) ) { + if ( Utils::is_order_eligible_auto_letterbox( $order_id ) ) { ?> ✓ settings->get_return_shipment_and_labels() && 'no' === $this->settings->get_return_shipment_and_labels_all() && 'NL' === $order->get_shipping_country() && 'NL' === Utils::get_base_country() && ! Utils::is_eligible_auto_letterbox( $order ) ) { + if ( 'shipping_return' === $this->settings->get_return_shipment_and_labels() && 'no' === $this->settings->get_return_shipment_and_labels_all() && 'NL' === $order->get_shipping_country() && 'NL' === Utils::get_base_country() && ! Utils::is_order_eligible_auto_letterbox( $order ) ) { ?>
@@ -627,7 +627,10 @@ public function postnl_activate_return_function() { wp_send_json_success(); } else { - throw new \Exception( esc_html__( print_r( $response['errorsPerBarcode'][0]['errors'][0], true ) ) ); + $error_message = isset($response['errorsPerBarcode'][0]['errors'][0]) ? $response['errorsPerBarcode'][0]['errors'][0] : 'Unknown error'; + + // Translators: %s is the error message. + throw new \Exception( sprintf( esc_html__( 'Error: %s', 'postnl-for-woocommerce' ), esc_html( $error_message ) ) ); } } catch ( \Exception $e ) { wp_send_json_error( diff --git a/src/Rest_API/Shipping/Item_Info.php b/src/Rest_API/Shipping/Item_Info.php index 2468eacd..0598fcaa 100644 --- a/src/Rest_API/Shipping/Item_Info.php +++ b/src/Rest_API/Shipping/Item_Info.php @@ -993,7 +993,8 @@ protected function check_insurance_amount_limit( $backend_data, $order_total ) { } // For EU shipments, validate that insurance does not exceed €5000 elseif ( ! $is_non_eu_shipment && 'yes' === $backend_data['insured_shipping'] && $order_total > 5000 ) { throw new \Exception( - __( 'Insurance amount for EU shipments cannot exceed €5000. Your total is: ' . $order_total, 'postnl-for-woocommerce' ) + // Translators: %s is the order total. + sprintf( esc_html__( 'Insurance amount for EU shipments cannot exceed €5000. Your total is: %d', 'postnl-for-woocommerce' ), $order_total ) ); } } diff --git a/src/Shipping_Method/PostNL.php b/src/Shipping_Method/PostNL.php index 17c788f0..8fb6d47a 100644 --- a/src/Shipping_Method/PostNL.php +++ b/src/Shipping_Method/PostNL.php @@ -91,6 +91,7 @@ public function instance_form_fields( $form_fields ) { $currency_symbol = get_woocommerce_currency_symbol(); $form_fields['minimum_for_free_shipping'] = array( + // Translators: %s is the currency symbol. 'title' => sprintf( esc_html__( 'Free shipping from %s', 'postnl-for-woocommerce' ), $currency_symbol ), 'type' => 'number', 'desc_tip' => esc_html__( 'Keep empty if you don’t want to use Free shipping', 'postnl-for-woocommerce' ), diff --git a/src/Utils.php b/src/Utils.php index 23376c0f..7684022f 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -652,53 +652,59 @@ public static function get_shipping_options( $order_id ) { return array_merge( $base_options, $destination_options ); } + /** + * Check if current cart is eligible for automatically use letterbox. + * + * @param \WC_Cart|int \WC_Cart. + * + * @return boolean + */ + public static function is_cart_eligible_auto_letterbox( $cart ) { + if ( ! in_array( WC()->customer->get_shipping_country(), Utils::get_available_country_for_letterbox(), true ) ) { + return false; + } + + return self::check_products_for_letterbox( $cart->get_cart() ); + } /** * Check if current order/cart is eligible for automatically use letterbox. * - * @param \WC_Order|\WC_Cart|int $order \WC_order, \WC_Cart or Order ID. + * @param \WC_Order|int $order \WC_order or Order ID. * * @return boolean */ - public static function is_eligible_auto_letterbox( $order ) { + public static function is_order_eligible_auto_letterbox( $order ) { if ( wc_get_base_location()['country'] == 'BE' ) { return false; } - // Check order + // Check if order id provided. if ( is_int( $order ) ) { $order = wc_get_order( $order ); } - if ( is_a( $order, 'WC_Order' ) ) { - if ( $order->meta_exists( '_postnl_letterbox' ) ) { - return (bool) $order->get_meta( '_postnl_letterbox', true ); - } - if ( ! in_array( $order->get_shipping_country(), Utils::get_available_country_for_letterbox(), true ) ) { - $order->update_meta_data( '_postnl_letterbox', false ); - $order->save(); + if ( ! is_a( $order, 'WC_Order' ) ) { + return false; + } - return false; - } - $products = $order->get_items(); + if ( $order->meta_exists( '_postnl_letterbox' ) ) { + return (bool) $order->get_meta( '_postnl_letterbox', true ); } - // Check cart items. - if ( is_a( $order, 'WC_Cart' ) ) { - if ( ! in_array( WC()->customer->get_shipping_country(), Utils::get_available_country_for_letterbox(), true ) ) { - return false; - } - $products = $order->get_cart(); + if ( ! in_array( $order->get_shipping_country(), Utils::get_available_country_for_letterbox(), true ) ) { + $order->update_meta_data( '_postnl_letterbox', false ); + $order->save_meta_data(); + + return false; } + $products = $order->get_items(); $is_eligible = self::check_products_for_letterbox( $products ); - // Save the state for the order. - if ( is_a( $order, 'WC_Order' ) ) { - $order->update_meta_data( '_postnl_letterbox', $is_eligible ); - $order->save(); - } + $order->update_meta_data( '_postnl_letterbox', $is_eligible ); + $order->save_meta_data(); return $is_eligible; }