Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update WP version and fix PCP errors #194

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion postnl-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
4 changes: 2 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/Emails/WC_Email_Smart_Return.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

/**
Expand All @@ -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' );
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Frontend/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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. <a href="%s" class="wc-backward">Return to shop</a>', 'woocommerce' ),
__( 'Sorry, your session has expired. <a href="%s" class="wc-backward">Return to shop</a>', 'postnl-for-woocommerce' ),
esc_url( wc_get_page_permalink( 'shop' ) )
);

Expand Down Expand Up @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion src/Frontend/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Order/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

Expand Down
3 changes: 3 additions & 0 deletions src/Order/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ 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',
);
}

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',
);
Expand Down Expand Up @@ -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, '<a href="' . $label_link . '" download>', '</a>' ),
'type' => 'success',
Expand Down
4 changes: 2 additions & 2 deletions src/Order/OrdersList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ) ) {
?>
<span class="postnl_eligible_auto_letterbox eligible">&#10003;</span>
<?php
Expand Down
7 changes: 5 additions & 2 deletions src/Order/Single.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function generate_pickup_points_html( $infos ) {
* Adds an 'Activate return function' button.
*/
public function activate_return_function_html( $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_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 ) ) {
?>
<hr id="postnl_break_2">
<p class="form-field">
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion src/Rest_API/Shipping/Item_Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Shipping_Method/PostNL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
Expand Down
54 changes: 30 additions & 24 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down