88
99namespace WPGraphQL \WooCommerce ;
1010
11+ use WPGraphQL \WooCommerce \Model \Coupon ;
12+ use WPGraphQL \WooCommerce \Model \Order ;
13+ use WPGraphQL \WooCommerce \Model \Product ;
14+
1115/**
1216 * Class ACF_Schema_Filters
1317 */
@@ -19,6 +23,7 @@ class ACF_Schema_Filters {
1923 public static function add_filters () {
2024 // Registers WooCommerce CPTs && taxonomies.
2125 add_filter ( 'graphql_acf_get_root_id ' , array ( __CLASS__ , 'resolve_crud_root_id ' ), 10 , 2 );
26+ add_filter ( 'graphql_acf_post_object_source ' , array ( __CLASS__ , 'resolve_post_object_source ' ), 10 , 2 );
2227 }
2328
2429 /**
@@ -38,4 +43,32 @@ public static function resolve_crud_root_id( $id, $root ) {
3843
3944 return $ id ;
4045 }
46+
47+ /**
48+ * Filters ACF "post_object" field type resolver to ensure that
49+ * the proper Type source is provided for WooCommerce CPTs.
50+ *
51+ * @param mixed|null $source source of the data being provided.
52+ * @param mixed|null $value Post ID.
53+ *
54+ * @return mixed|null
55+ */
56+ public static function resolve_post_object_source ( $ source , $ value ) {
57+ $ post = get_post ( $ value );
58+ if ( $ post instanceof \WP_Post ) {
59+ switch ( $ post ->post_type ) {
60+ case 'shop_coupon ' :
61+ $ source = new Coupon ( $ post ->ID );
62+ break ;
63+ case 'shop_order ' :
64+ $ source = new Order ( $ post ->ID );
65+ break ;
66+ case 'product ' :
67+ $ source = new Product ( $ post ->ID );
68+ break ;
69+ }
70+ }
71+
72+ return $ source ;
73+ }
4174}
0 commit comments