Skip to content

Commit 7fd709e

Browse files
committed
Fix Product Variation Shipping Class
1 parent 5f924bb commit 7fd709e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

includes/model/class-product-variation.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,19 @@ protected function init() {
231231
'shipping_class_id' => function () {
232232
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
233233
},
234+
'shippingClassId' => function () {
235+
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
236+
},
237+
'shippingClass' => function () {
238+
$shipping_class_id = $this->wc_data->get_shipping_class_id();
239+
$shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );
240+
241+
if ( ! is_wp_error( $shipping_class_term ) && is_a( $shipping_class_term, 'WP_Term' ) ) {
242+
$shipping_class = $shipping_class_term;
243+
}
244+
245+
return $shipping_class ?? null;
246+
},
234247
'image_id' => function () {
235248
return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null;
236249
},

includes/model/class-product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ protected function init() {
413413
return ! empty( $this->wc_data->get_height() ) ? $this->wc_data->get_height() : null;
414414
},
415415
'shippingClassId' => function () {
416-
return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_shipping_class_id() : null;
416+
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
417417
},
418418
'shippingRequired' => function () {
419419
return $this->wc_data->needs_shipping();

includes/type/interface/class-product-variation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ public static function get_fields() {
242242
'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ),
243243
],
244244
'shippingClass' => [
245-
'type' => 'String',
245+
'type' => 'ShippingClass',
246246
'description' => __( 'Product variation shipping class', 'wp-graphql-woocommerce' ),
247247
],
248248
'catalogVisibility' => [

0 commit comments

Comments
 (0)