mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
- Update plugin version to 1.0.0 and bump dependency requirements (WP 6.3+, PHP 8.1+, WC 9.0+, WPGraphQL 2.0+) - Update README.md, README.txt, and docs with v1.0.0 features - Add building-a-woocommerce-admin-app.md documenting WC Settings API, product CRUD, product attribute management, and refund operations - Update settings.md with new v1.0.0 settings documentation - Update installation.md with version prerequisites - Remove obsolete toc.md (replaced by docs/README.md) - Update @since tags from TBD to 1.0.0
81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Registers WooCommerce taxonomies to the GraphQL schema.
|
|
*
|
|
* @package \WPGraphQL\WooCommerce
|
|
* @since 1.0.0
|
|
*/
|
|
|
|
namespace WPGraphQL\WooCommerce;
|
|
|
|
/**
|
|
* Class Taxonomies
|
|
*/
|
|
class Taxonomies {
|
|
/**
|
|
* Register filters.
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function init() {
|
|
add_filter( 'register_taxonomy_args', [ self::class, 'register_taxonomy_args' ], 10, 2 );
|
|
}
|
|
|
|
/**
|
|
* Registers WooCommerce taxonomies to be used in GraphQL schema
|
|
*
|
|
* @param array $args - allowed taxonomies.
|
|
* @param string $taxonomy - name of taxonomy being checked.
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function register_taxonomy_args( $args, $taxonomy ) {
|
|
if ( 'product_type' === $taxonomy ) {
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = 'productType';
|
|
$args['graphql_plural_name'] = 'productTypes';
|
|
}
|
|
|
|
if ( 'product_visibility' === $taxonomy ) {
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = 'visibleProduct';
|
|
$args['graphql_plural_name'] = 'visibleProducts';
|
|
}
|
|
|
|
if ( 'product_cat' === $taxonomy ) {
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = 'productCategory';
|
|
$args['graphql_plural_name'] = 'productCategories';
|
|
}
|
|
|
|
if ( 'product_tag' === $taxonomy ) {
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = 'productTag';
|
|
$args['graphql_plural_name'] = 'productTags';
|
|
}
|
|
|
|
if ( 'product_shipping_class' === $taxonomy ) {
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = 'shippingClass';
|
|
$args['graphql_plural_name'] = 'shippingClasses';
|
|
}
|
|
|
|
if ( 'product_brand' === $taxonomy ) {
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = 'productBrand';
|
|
$args['graphql_plural_name'] = 'productBrands';
|
|
}
|
|
|
|
// Filter product attributes taxonomies.
|
|
$attributes = WP_GraphQL_WooCommerce::get_product_attribute_taxonomies();
|
|
if ( in_array( $taxonomy, $attributes, true ) ) {
|
|
$singular_name = graphql_format_field_name( $taxonomy );
|
|
$args['show_in_graphql'] = true;
|
|
$args['graphql_single_name'] = $singular_name;
|
|
$args['graphql_plural_name'] = 'all' . ucFirst( $singular_name );
|
|
}
|
|
|
|
return $args;
|
|
}
|
|
}
|