From f9a10106b643a11317c7fd788216f0b85170e941 Mon Sep 17 00:00:00 2001 From: taur Date: Wed, 17 May 2017 11:59:53 +0200 Subject: [PATCH 1/4] Added rest API support Can't access access the gift wrap information via rest APi without this. --- woocommerce-product-gift-wrap.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/woocommerce-product-gift-wrap.php b/woocommerce-product-gift-wrap.php index 9edbf32..0f7fb77 100644 --- a/woocommerce-product-gift-wrap.php +++ b/woocommerce-product-gift-wrap.php @@ -310,3 +310,27 @@ public function save_admin_settings() { } new WC_Product_Gift_Wrap(); + +/** + * callbacks for WP rest api + */ +function slug_get_product_meta_cb($object, $field_name, $request) { + return get_post_meta( $object['id'], $field_name ); +} + + function slug_update_product_meta_cb( $value, $object, $field_name ) { + return update_post_meta( $object['id'], $field_name, $value ); +} + +add_action('rest_api_init', function() { + register_api_field('product', '_is_gift_wrappable', array( + 'get_callback' => 'slug_get_product_meta_cb', + 'update_callback' => 'slug_update_product_meta_cb', + 'schema' => null + )); + register_api_field('product', '_gift_wrap_cost', array( + 'get_callback' => 'slug_get_product_meta_cb', + 'update_callback' => 'slug_update_product_meta_cb', + 'schema' => null + )); +}); From 7846ea2f8dd61e58fd6ce2ba4467f2ab81efe1df Mon Sep 17 00:00:00 2001 From: taur Date: Thu, 18 May 2017 14:01:13 +0200 Subject: [PATCH 2/4] register_api_field deprecated warning updated these function calls --- woocommerce-product-gift-wrap.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/woocommerce-product-gift-wrap.php b/woocommerce-product-gift-wrap.php index 0f7fb77..6465407 100644 --- a/woocommerce-product-gift-wrap.php +++ b/woocommerce-product-gift-wrap.php @@ -323,12 +323,12 @@ function slug_update_product_meta_cb( $value, $object, $field_name ) { } add_action('rest_api_init', function() { - register_api_field('product', '_is_gift_wrappable', array( + register_rest_field('product', '_is_gift_wrappable', array( 'get_callback' => 'slug_get_product_meta_cb', 'update_callback' => 'slug_update_product_meta_cb', 'schema' => null )); - register_api_field('product', '_gift_wrap_cost', array( + register_rest_field('product', '_gift_wrap_cost', array( 'get_callback' => 'slug_get_product_meta_cb', 'update_callback' => 'slug_update_product_meta_cb', 'schema' => null From 653f343e7e356645b9693779498c84d257348c17 Mon Sep 17 00:00:00 2001 From: taur Date: Fri, 19 May 2017 14:20:08 +0200 Subject: [PATCH 3/4] Update woocommerce-product-gift-wrap.php --- woocommerce-product-gift-wrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce-product-gift-wrap.php b/woocommerce-product-gift-wrap.php index 6465407..d1d6f2b 100644 --- a/woocommerce-product-gift-wrap.php +++ b/woocommerce-product-gift-wrap.php @@ -319,7 +319,7 @@ function slug_get_product_meta_cb($object, $field_name, $request) { } function slug_update_product_meta_cb( $value, $object, $field_name ) { - return update_post_meta( $object['id'], $field_name, $value ); + return update_post_meta( $object->id, $field_name, $value ); } add_action('rest_api_init', function() { From fe4fecdaa96063f3a15b7e8e9a1043f62951ad10 Mon Sep 17 00:00:00 2001 From: taur Date: Wed, 12 Jul 2017 16:25:19 +0200 Subject: [PATCH 4/4] Update woocommerce-product-gift-wrap.php --- woocommerce-product-gift-wrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/woocommerce-product-gift-wrap.php b/woocommerce-product-gift-wrap.php index d1d6f2b..0a6e97c 100644 --- a/woocommerce-product-gift-wrap.php +++ b/woocommerce-product-gift-wrap.php @@ -319,7 +319,7 @@ function slug_get_product_meta_cb($object, $field_name, $request) { } function slug_update_product_meta_cb( $value, $object, $field_name ) { - return update_post_meta( $object->id, $field_name, $value ); + return update_post_meta( $object->ID, $field_name, $value ); } add_action('rest_api_init', function() {