diff --git a/includes/API/Product_Categories.php b/includes/API/Product_Categories.php index ff25173..dfa0c5e 100644 --- a/includes/API/Product_Categories.php +++ b/includes/API/Product_Categories.php @@ -49,4 +49,33 @@ public function product_categories_response( WP_REST_Response $response, object return $response; } + + /** + * Returns array of all product category ids + * + * @param array $fields + * + * @return array + */ + public function get_all_posts( array $fields = array() ): array { + $args = array( + 'taxonomy' => 'product_cat', + 'hide_empty' => false, + 'fields' => 'ids', + ); + + $product_category_ids = get_terms( $args ); + + // Convert the array of cat IDs to an array of objects with cat IDs as integers + return array_map( array( $this, 'format_id' ), $product_category_ids ); + } + + /** + * @param string $product_category_id + * + * @return object + */ + private function format_id( string $product_category_id ): object { + return (object) array( 'id' => (int) $product_category_id ); + } } diff --git a/includes/API/Product_Tags.php b/includes/API/Product_Tags.php index 38d7028..ba23acd 100644 --- a/includes/API/Product_Tags.php +++ b/includes/API/Product_Tags.php @@ -49,4 +49,33 @@ public function product_tags_response( WP_REST_Response $response, object $item, return $response; } + + /** + * Returns array of all product tag ids + * + * @param array $fields + * + * @return array + */ + public function get_all_posts( array $fields = array() ): array { + $args = array( + 'taxonomy' => 'product_tag', + 'hide_empty' => false, + 'fields' => 'ids', + ); + + $product_tag_ids = get_terms( $args ); + + // Convert the array of tag IDs to an array of objects with tag IDs as integers + return array_map( array( $this, 'format_id' ), $product_tag_ids ); + } + + /** + * @param string $product_tag_id + * + * @return object + */ + private function format_id( string $product_tag_id ): object { + return (object) array( 'id' => (int) $product_tag_id ); + } } diff --git a/includes/Gateways.php b/includes/Gateways.php index 23a68b6..e7f359f 100644 --- a/includes/Gateways.php +++ b/includes/Gateways.php @@ -25,7 +25,7 @@ public function __construct() { * BEWARE: some gateways/themes/plugins call this very early on every page!! * We cannot guarantee that $wp is set, so we cannot use woocommerce_pos_request. * - * @param $gateways + * @param array | null $gateways * * @return array */ @@ -49,11 +49,13 @@ public function payment_gateways( array $gateways ) { * - Order and set default order * - Also going to remove icons from the gateways * - * @param array $gateways + * - BUG: a user with WooCommerce Blocks is getting null for $gateways? + * + * @param array | null $gateways * * @return array */ - public function available_payment_gateways( array $gateways ): array { + public function available_payment_gateways( ?array $gateways ): array { // early exit if ( ! woocommerce_pos_request() ) { return $gateways;