Skip to content

Commit ee0d3ae

Browse files
committed
ProductVariationg Shipping Class Fix
1 parent 36e79d3 commit ee0d3ae

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

includes/model/class-product-variation.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ protected function init() {
215215
'salePriceRaw' => function () {
216216
return ! empty( $this->wc_data->get_sale_price() ) ? $this->wc_data->get_sale_price() : null;
217217
},
218+
'shippingClass' => function () {
219+
$shipping_class_id = $this->wc_data->get_shipping_class_id();
220+
$shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );
221+
222+
if ( ! is_wp_error( $shipping_class_term ) && is_a( $shipping_class_term, 'WP_Term' ) ) {
223+
$shipping_class = $shipping_class_term;
224+
}
225+
226+
return $shipping_class ?? null;
227+
},
218228

219229
/**
220230
* Connection resolvers fields

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
@@ -244,7 +244,7 @@ public static function get_fields() {
244244
'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ),
245245
],
246246
'shippingClass' => [
247-
'type' => 'String',
247+
'type' => 'ShippingClass',
248248
'description' => __( 'Product variation shipping class', 'wp-graphql-woocommerce' ),
249249
],
250250
'catalogVisibility' => [

0 commit comments

Comments
 (0)