Skip to content

Commit

Permalink
Fix Product Variation Shipping Class
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiebel committed Oct 4, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent 5f924bb commit 7fd709e
Showing 3 changed files with 15 additions and 2 deletions.
13 changes: 13 additions & 0 deletions includes/model/class-product-variation.php
Original file line number Diff line number Diff line change
@@ -231,6 +231,19 @@ protected function init() {
'shipping_class_id' => function () {
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
},
'shippingClassId' => function () {
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
},
'shippingClass' => function () {
$shipping_class_id = $this->wc_data->get_shipping_class_id();
$shipping_class_term = get_term( $shipping_class_id, 'product_shipping_class' );

if ( ! is_wp_error( $shipping_class_term ) && is_a( $shipping_class_term, 'WP_Term' ) ) {

Check failure on line 241 in includes/model/class-product-variation.php

GitHub Actions / Testing WooGraphQL code quality w/ PHPStan

Parameter #1 $object_or_class of function is_a expects object, WP_Term|null given.
$shipping_class = $shipping_class_term;
}

return $shipping_class ?? null;
},
'image_id' => function () {
return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_image_id() : null;
},
2 changes: 1 addition & 1 deletion includes/model/class-product.php
Original file line number Diff line number Diff line change
@@ -413,7 +413,7 @@ protected function init() {
return ! empty( $this->wc_data->get_height() ) ? $this->wc_data->get_height() : null;
},
'shippingClassId' => function () {
return ! empty( $this->wc_data->get_image_id() ) ? $this->wc_data->get_shipping_class_id() : null;
return ! empty( $this->wc_data->get_shipping_class_id() ) ? $this->wc_data->get_shipping_class_id() : null;
},
'shippingRequired' => function () {
return $this->wc_data->needs_shipping();
2 changes: 1 addition & 1 deletion includes/type/interface/class-product-variation.php
Original file line number Diff line number Diff line change
@@ -242,7 +242,7 @@ public static function get_fields() {
'description' => __( 'Product variation purchase_note', 'wp-graphql-woocommerce' ),
],
'shippingClass' => [
'type' => 'String',
'type' => 'ShippingClass',
'description' => __( 'Product variation shipping class', 'wp-graphql-woocommerce' ),
],
'catalogVisibility' => [

0 comments on commit 7fd709e

Please sign in to comment.