From e02c1953086973f38c4535797dbfef806d3d52db Mon Sep 17 00:00:00 2001 From: Zed Date: Tue, 20 Sep 2022 23:21:14 +0430 Subject: [PATCH 1/3] fix: Limited address and name length --- inc/MetaBox.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/inc/MetaBox.php b/inc/MetaBox.php index 7f6d40e..f8e9790 100644 --- a/inc/MetaBox.php +++ b/inc/MetaBox.php @@ -6,6 +6,10 @@ use WP_Encryption\Encryption; class MetaBox { + private $address_length = 185; + private $name_length = 17; + private $comment_length = 60; + public function add_meta_boxes () { if ( get_post_type() == 'shop_order' && isset( $_GET[ 'post' ] ) ) { @@ -135,6 +139,8 @@ public function delivery_step_1( $order ) { $destination_city = $order->get_shipping_city(); $destination_city = Location::get_city_by_name($destination_city); $destination_address = $destination_city['name'] . ' ' . $order->get_billing_address_1() . ' ' . $order->get_billing_address_2(); + if( mb_strlen($destination_address) > $this->address_length ) + $destination_address = mb_substr($destination_address, 0, $this->address_length); $store_address = get_option( 'woocommerce_store_address' ) . get_option( 'woocommerce_store_address_2' ); $total_weight = 0; @@ -301,10 +307,10 @@ public function ajax_saving_options_step_2() { ], ], 'receiver' => [ - 'name' => $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name(), + 'name' => ( (mb_strlen($order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name()) > $this->name_length) ? mb_substr($order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name(), 0, $this->name_length): $order->get_shipping_first_name() . ' ' . $order->get_shipping_last_name()), 'contact' => [ 'postal_code' => $order->get_shipping_postcode(), - 'address' => $order->get_shipping_address_1(), + 'address' => ( mb_strlen($order->get_shipping_address_1()) > $this->address_length) ? (mb_substr($order->get_shipping_address_1(), 0 , $this->address_length)): $order->get_shipping_address_1(), 'city' => $destination_city['code'], 'phone_number' => $order->get_billing_phone(), ], @@ -323,7 +329,7 @@ public function ajax_saving_options_step_2() { ] ], 'payment_type' => 1, - 'receiver_comment' => $order->get_customer_note(), + 'receiver_comment' => ( mb_strlen($order->get_customer_note())> $this->comment_length ? mb_substr($order->get_customer_note(),0 , $this->comment_length): $order->get_customer_note()), 'service_type' => 'regular', 'provider_code' => sanitize_text_field( $_POST['provider_code'] ), ]; From 739463873773d75cb5bb549a2b55302ee9c0f0fe Mon Sep 17 00:00:00 2001 From: Zed Date: Fri, 23 Sep 2022 19:01:48 +0330 Subject: [PATCH 2/3] fix: Add new fields to metabox add store name, customer name, description to metabox make source and destination enabled --- assets/js/admin.js | 11 +++++++ inc/MetaBox.php | 68 +++++++++++++++++++++++++++++++++++---- inc/Podro_Order_Table.php | 2 ++ 3 files changed, 74 insertions(+), 7 deletions(-) diff --git a/assets/js/admin.js b/assets/js/admin.js index 17dc847..8e44763 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -95,9 +95,18 @@ height: $('input[name=pod_height]').val(), depth: $('input[name=pod_depth]').val(), order_id: $('input[name=pod_order_id]').val(), + pod_store_name: $('input[name=pod_store_name]').val(), + pod_source_city: $('textarea[name=pod_source_city]').val(), + pod_destination_city: $('textarea[name=pod_destination_city]').val(), + pod_user_billing_name: $('input[name=pod_user_billing_name]').val(), + pod_user_billing_family: $('input[name=pod_user_billing_family]').val(), + pod_customer_note: $('textarea[name=pod_customer_note]').val(), + + }; if ( pod_validate_step_1( data ) ) { + pod_ajax( data, _callback_step_1 ); } }) @@ -384,7 +393,9 @@ } function _callback_step_1( response ) { + if ( response.success ) { + let data = { weight: $('input[name=pod_weight]').val(), totalprice: $('input[name=pod_totalprice]').val(), diff --git a/inc/MetaBox.php b/inc/MetaBox.php index f8e9790..e701a8f 100644 --- a/inc/MetaBox.php +++ b/inc/MetaBox.php @@ -176,19 +176,50 @@ public function delivery_step_1( $order ) { $height = $dimensions['height']; $length = $dimensions['length']; } + + $user_billing_name = $order->get_billing_first_name(); + $user_billing_family = $order->get_billing_last_name(); + + $store_name = $this->get_store_name(); + $customer_note = $order->get_customer_note(); + + $option_pod_source_city = get_option('pod_source_city'); + $option_pod_store_name = get_option('pod_store_name'); + + $option_pod_source_city = ( false == $option_pod_source_city ) ? $store_address : $option_pod_source_city; + $option_pod_store_name = ( false == $option_pod_store_name ) ? $store_name : $option_pod_store_name; + + + ?>