From b503e270df6d5f4c48cc6a67fc527f51c0840046 Mon Sep 17 00:00:00 2001 From: Timo Janssen Date: Fri, 27 Sep 2019 20:12:40 +0200 Subject: [PATCH 1/2] Adding preferred_service_level to rest api --- includes/checkout.php | 41 +++++++++++++++++++++++++++++++++++ includes/wcwuunder-create.php | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/includes/checkout.php b/includes/checkout.php index 5ae51ca..d2d9c35 100644 --- a/includes/checkout.php +++ b/includes/checkout.php @@ -53,6 +53,29 @@ function wcwp_parcelshop_html() EOT; } +/** + * Returns the filter (preferred service level) that is set in the Wuunder config + * + * @param $shipping_method + * @return + */ +function wcwp_get_filter_from_shippingmethod($shipping_method ) { + if ( false !== strpos( $shipping_method, ':' ) ) { + $shipping_method = explode( ':', $shipping_method )[0]; + } + if ( $shipping_method === get_option( 'wc_wuunder_mapping_method_1' ) ) { + return get_option( 'wc_wuunder_mapping_filter_1' ); + } elseif ( $shipping_method === get_option( 'wc_wuunder_mapping_method_2' ) ) { + return get_option( 'wc_wuunder_mapping_filter_2' ); + } elseif ( $shipping_method === get_option( 'wc_wuunder_mapping_method_3') ) { + return get_option( 'wc_wuunder_mapping_filter_3' ); + } elseif ( $shipping_method === get_option( 'wc_wuunder_mapping_method_4' ) ) { + return get_option( 'wc_wuunder_mapping_filter_4' ); + } else { + return ''; + } +} + // Field added for the parcelshop_id, so that it can be requested from backend add_action( 'woocommerce_after_order_notes', 'wcwp_add_parcelshop_id_field' ); function wcwp_add_parcelshop_id_field($checkout ) { @@ -71,6 +94,24 @@ function wcwp_add_parcelshop_id_field($checkout ) { ), $checkout->get_value( 'parcelshop_country' ) ); } +/* + * Add a referanse field to the Order API response. +*/ +function prefix_wc_rest_prepare_order_object( $response, $object, $request ) { + $shipping_method_id = null; + try { + $order = new WC_Order($object->get_id()); + $shipping_object = $order->get_items('shipping'); + $shipping_method_id = wcwp_get_filter_from_shippingmethod(reset($shipping_object)->get_method_id()); + } catch (Exception $e) { + + } + $response->data['wuunder_preferred_service_level'] = $shipping_method_id; + + return $response; +} +add_filter( 'woocommerce_rest_prepare_shop_order_object', 'prefix_wc_rest_prepare_order_object', 10, 3 ); + // Save / Send the parcelshop id add_action( 'woocommerce_checkout_update_order_meta', 'wcwp_update_parcelshop_id' ); function wcwp_update_parcelshop_id( $order_id ) { diff --git a/includes/wcwuunder-create.php b/includes/wcwuunder-create.php index a4d5576..530c9b1 100644 --- a/includes/wcwuunder-create.php +++ b/includes/wcwuunder-create.php @@ -486,7 +486,7 @@ public function wcwp_add_meta_boxes() { add_meta_box( 'wpo_wcpdf-box', __( 'Wuunder', 'woocommerce-wuunder' ), - array( $this, 'sidebar_box_content' ), + array( $this, 'wcwp_sidebar_box_content' ), 'shop_order', 'side', 'default' From 1def63fdc7b4a08722203f9298b5bbfc0aa4b834 Mon Sep 17 00:00:00 2001 From: Timo Janssen Date: Fri, 27 Sep 2019 20:14:42 +0200 Subject: [PATCH 2/2] upd version, changelog --- CHANGELOG.md | 5 +++++ includes/wcwuunder-create.php | 2 +- woocommerce-wuunder.php | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b7a491a..8e244cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). ## Released +## [2.7.4](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.4) - 2019-09-27 + +### Added +- Preferred_service_level to Woocommerce REST API Orders resourcelist + ## [2.7.3](https://github.com/kabisa/wuunder-webshopplugin-woocommerce/tag/2.7.3) - 2019-09-25 ### Fix diff --git a/includes/wcwuunder-create.php b/includes/wcwuunder-create.php index 530c9b1..afd80d4 100644 --- a/includes/wcwuunder-create.php +++ b/includes/wcwuunder-create.php @@ -12,7 +12,7 @@ public function __construct() { $this->version_obj = array( 'product' => 'Woocommerce extension', 'version' => array( - 'build' => '2.7.3', + 'build' => '2.7.4', 'plugin' => '2.0' ), 'platform' => array( 'name' => 'Woocommerce', diff --git a/woocommerce-wuunder.php b/woocommerce-wuunder.php index a729694..3b7b894 100644 --- a/woocommerce-wuunder.php +++ b/woocommerce-wuunder.php @@ -3,7 +3,7 @@ * Plugin Name: WooCommerce Wuunder * Plugin URI: https://wearewuunder.com/wuunder-voor-webshops/ * Description: Wuunder shipping plugin - * Version: 2.7.3 + * Version: 2.7.4 * Author: Wuunder * Author URI: http://wearewuunder.com */ @@ -57,7 +57,7 @@ class Woocommerce_Wuunder { public static $plugin_path; public static $plugin_basename; - const VERSION = '2.7.3'; + const VERSION = '2.7.4'; public function __construct() {