WC_Brands
in package
WC_Brands class.
Important: For internal use only by the Automattic\WooCommerce\Internal\Brands package.
Tags
Table of Contents
- $template_url : mixed|null
- Template URL -- filterable.
- __construct() : mixed
- __construct function.
- add_body_class() : mixed
- Adds classes to brand taxonomy pages.
- add_brand_products_shortcode_atts() : array<string|int, mixed>
- Adds the "brand" attribute to the list of WooCommerce products shortcode attributes.
- add_brands_to_terms() : array<string|int, mixed>
- Add product_brand to the taxonomies overridden for the original term count.
- add_structured_data() : array<string|int, mixed>
- Add structured data to product page.
- body_class() : mixed
- Adds filter for introducing CSS classes.
- brand_description() : mixed
- Displays brand description.
- configure_product_brand_block() : array<string|int, mixed>
- Configures the attributes for the hooked product brand terms block.
- duplicate_add_product_brand_terms() : mixed
- After product was added check if there are temporary brands and add them officially and remove the temporary brands.
- duplicate_store_temporary_brands() : WC_Product
- Temporarily tag a post with meta before it is saved in order to allow us to be able to use the meta when the product is saved to add the brands when an ID has been generated.
- get_brand_products_query_args() : array<string|int, mixed>
- Adds the taxonomy query to the WooCommerce products shortcode query arguments.
- hook_product_brand_block() : array<string|int, mixed>
- Hooks the product brand terms block into single product templates.
- init_taxonomy() : mixed
- Initializes brand taxonomy.
- init_widgets() : mixed
- Initializes brand widgets.
- invalidate_wc_layered_nav_counts_cache() : void
- Invalidates the layered nav counts cache.
- output_brand_products() : string
- Displays brand products.
- output_product_brand() : string
- Displays product brand.
- output_product_brand_list() : string
- Displays product brand list.
- output_product_brand_thumbnails() : void
- Displays brand thumbnails.
- output_product_brand_thumbnails_description() : void
- Displays brand thumbnails description.
- post_type_link() : string
- Filter to allow product_brand in the permalinks for products.
- recount_after_stock_change() : mixed
- Recount the brands after the stock amount changes.
- recount_all_brands() : mixed
- Recount all brands.
- register_hooks() : mixed
- Register our hooks
- register_shortcodes() : mixed
- Registers shortcodes.
- reset_layered_nav_counts_on_status_change() : void
- Reset Layered Nav cached counts on product status change.
- rest_api_add_brands_to_product() : mixed
- Add brands in product response.
- rest_api_filter_products_by_brand() : array<string|int, mixed>
- Filters products by taxonomy product_brand.
- rest_api_maybe_set_brands() : void
- Maybe set brands when requesting PUT /products/<id>.
- rest_api_prepare_brands_to_product() : WP_REST_Response
- Prepare brands in product response.
- rest_api_product_collection_params() : array<string|int, mixed>
- Documents additional query params for collections of products.
- rest_api_register_routes() : void
- Register REST API route for /products/brands.
- show_brand() : mixed
- Displays brand.
- styles() : mixed
- Enqueues styles.
- template_loader() : mixed
- Handles template usage so that we can use our own templates instead of the themes.
- update_product_query_tax_query() : array<string|int, mixed>
- Update the main product fetch query to filter by selected brands.
- wc_brands_on_block_template_register() : mixed
- Add a new block to the template.
- woocommerce_brands_update_layered_nav_link() : string
- Injects Brands filters into layered nav links.
- get_brand_name_first_character() : string
- Get the first letter of the brand name, returning lowercase and without accents.
- remove_terms_with_empty_products() : array<string|int, WP_Term>
- Remove terms with empty products.
- template_already_has_brand_block() : bool
- Check if the template already contains a product brand block.
Properties
$template_url
Template URL -- filterable.
public
mixed|null
$template_url
Methods
__construct()
__construct function.
public
__construct() : mixed
Return values
mixed —add_body_class()
Adds classes to brand taxonomy pages.
public
add_body_class(array<string|int, mixed> $classes) : mixed
Parameters
- $classes : array<string|int, mixed>
-
Classes array.
Return values
mixed —add_brand_products_shortcode_atts()
Adds the "brand" attribute to the list of WooCommerce products shortcode attributes.
public
static add_brand_products_shortcode_atts(array<string|int, mixed> $out, array<string|int, mixed> $pairs, array<string|int, mixed> $atts, string $shortcode) : array<string|int, mixed>
Parameters
- $out : array<string|int, mixed>
-
The output array of shortcode attributes.
- $pairs : array<string|int, mixed>
-
The supported attributes and their defaults.
- $atts : array<string|int, mixed>
-
The user defined shortcode attributes.
- $shortcode : string
-
The shortcode name.
Return values
array<string|int, mixed> — The output array of shortcode attributes.add_brands_to_terms()
Add product_brand to the taxonomies overridden for the original term count.
public
add_brands_to_terms(array<string|int, mixed> $taxonomies) : array<string|int, mixed>
Parameters
- $taxonomies : array<string|int, mixed>
-
List of taxonomies.
Return values
array<string|int, mixed> —add_structured_data()
Add structured data to product page.
public
add_structured_data(array<string|int, mixed> $markup) : array<string|int, mixed>
Parameters
- $markup : array<string|int, mixed>
-
Markup.
Return values
array<string|int, mixed> — $markupbody_class()
Adds filter for introducing CSS classes.
public
body_class() : mixed
Return values
mixed —brand_description()
Displays brand description.
public
brand_description() : mixed
Return values
mixed —configure_product_brand_block()
Configures the attributes for the hooked product brand terms block.
public
configure_product_brand_block(array<string|int, mixed> $parsed_hooked_block, string $hooked_block_type, int $relative_position, array<string|int, mixed> $parsed_anchor_block, WP_Block_Template $context) : array<string|int, mixed>
Parameters
- $parsed_hooked_block : array<string|int, mixed>
-
The parsed hooked block.
- $hooked_block_type : string
-
The type of hooked block.
- $relative_position : int
-
The relative position of the hooked block.
- $parsed_anchor_block : array<string|int, mixed>
-
The parsed anchor block.
- $context : WP_Block_Template
-
The context of the block.
Return values
array<string|int, mixed> — The parsed hooked block.duplicate_add_product_brand_terms()
After product was added check if there are temporary brands and add them officially and remove the temporary brands.
public
duplicate_add_product_brand_terms(int $product_id) : mixed
Parameters
- $product_id : int
Tags
Return values
mixed —duplicate_store_temporary_brands()
Temporarily tag a post with meta before it is saved in order to allow us to be able to use the meta when the product is saved to add the brands when an ID has been generated.
public
duplicate_store_temporary_brands(WC_Product $duplicate, mixed $original) : WC_Product
Parameters
- $duplicate : WC_Product
- $original : mixed
Return values
WC_Product — $originalget_brand_products_query_args()
Adds the taxonomy query to the WooCommerce products shortcode query arguments.
public
static get_brand_products_query_args(array<string|int, mixed> $query_args, array<string|int, mixed> $attributes, string $type) : array<string|int, mixed>
Parameters
- $query_args : array<string|int, mixed>
- $attributes : array<string|int, mixed>
- $type : string
Return values
array<string|int, mixed> —hook_product_brand_block()
Hooks the product brand terms block into single product templates.
public
hook_product_brand_block(array<string|int, mixed> $hooked_block_types, int $relative_position, string $anchor_block_type, WP_Block_Template $context) : array<string|int, mixed>
Parameters
- $hooked_block_types : array<string|int, mixed>
-
The array of hooked block types.
- $relative_position : int
-
The relative position of the hooked block.
- $anchor_block_type : string
-
The type of anchor block.
- $context : WP_Block_Template
-
The context of the block.
Return values
array<string|int, mixed> — The array of hooked block types.init_taxonomy()
Initializes brand taxonomy.
public
static init_taxonomy() : mixed
Return values
mixed —init_widgets()
Initializes brand widgets.
public
init_widgets() : mixed
Return values
mixed —invalidate_wc_layered_nav_counts_cache()
Invalidates the layered nav counts cache.
public
invalidate_wc_layered_nav_counts_cache() : void
Return values
void —output_brand_products()
Displays brand products.
public
output_brand_products(array<string|int, mixed> $atts) : string
Parameters
- $atts : array<string|int, mixed>
Return values
string —output_product_brand()
Displays product brand.
public
output_product_brand(array<string|int, mixed> $atts) : string
Parameters
- $atts : array<string|int, mixed>
-
Attributes from the shortcode.
Return values
string — The generated output.output_product_brand_list()
Displays product brand list.
public
output_product_brand_list(array<string|int, mixed> $atts) : string
Parameters
- $atts : array<string|int, mixed>
-
Attributes from the shortcode.
Return values
string —output_product_brand_thumbnails()
Displays brand thumbnails.
public
output_product_brand_thumbnails(mixed $atts) : void
Parameters
- $atts : mixed
Return values
void —output_product_brand_thumbnails_description()
Displays brand thumbnails description.
public
output_product_brand_thumbnails_description(mixed $atts) : void
Parameters
- $atts : mixed
Return values
void —post_type_link()
Filter to allow product_brand in the permalinks for products.
public
post_type_link(string $permalink, WP_Post $post) : string
Parameters
- $permalink : string
-
The existing permalink URL.
- $post : WP_Post
-
The post.
Return values
string —recount_after_stock_change()
Recount the brands after the stock amount changes.
public
recount_after_stock_change(int $product_id) : mixed
Parameters
- $product_id : int
-
Product ID.
Return values
mixed —recount_all_brands()
Recount all brands.
public
recount_all_brands() : mixed
Return values
mixed —register_hooks()
Register our hooks
public
register_hooks() : mixed
Return values
mixed —register_shortcodes()
Registers shortcodes.
public
register_shortcodes() : mixed
Return values
mixed —reset_layered_nav_counts_on_status_change()
Reset Layered Nav cached counts on product status change.
public
reset_layered_nav_counts_on_status_change( $new_status, $old_status, $post) : void
Parameters
Return values
void —rest_api_add_brands_to_product()
Add brands in product response.
public
rest_api_add_brands_to_product(WC_Data $product, WP_REST_Request $request[, bool $creating = true ]) : mixed
Parameters
- $product : WC_Data
-
Inserted product object.
- $request : WP_REST_Request
-
Request object.
- $creating : bool = true
-
True when creating object, false when updating.
Tags
Return values
mixed —rest_api_filter_products_by_brand()
Filters products by taxonomy product_brand.
public
rest_api_filter_products_by_brand(array<string|int, mixed> $args, WP_REST_Request $request) : array<string|int, mixed>
Parameters
- $args : array<string|int, mixed>
-
Request args.
- $request : WP_REST_Request
-
Request data.
Tags
Return values
array<string|int, mixed> — Request args.rest_api_maybe_set_brands()
Maybe set brands when requesting PUT /products/<id>.
public
rest_api_maybe_set_brands(WP_Post $post, WP_REST_Request $request) : void
Parameters
- $post : WP_Post
-
Post object
- $request : WP_REST_Request
-
Request object
Tags
Return values
void —rest_api_prepare_brands_to_product()
Prepare brands in product response.
public
rest_api_prepare_brands_to_product(WP_REST_Response $response, WP_Post|WC_Data $post) : WP_REST_Response
Parameters
- $response : WP_REST_Response
-
The response object.
- $post : WP_Post|WC_Data
-
Post object or WC object.
Tags
Return values
WP_REST_Response —rest_api_product_collection_params()
Documents additional query params for collections of products.
public
rest_api_product_collection_params(array<string|int, mixed> $params, WP_Post_Type $post_type) : array<string|int, mixed>
Parameters
- $params : array<string|int, mixed>
-
JSON Schema-formatted collection parameters.
- $post_type : WP_Post_Type
-
Post type object.
Tags
Return values
array<string|int, mixed> — JSON Schema-formatted collection parameters.rest_api_register_routes()
Register REST API route for /products/brands.
public
rest_api_register_routes() : void
Tags
Return values
void —show_brand()
Displays brand.
public
show_brand() : mixed
Return values
mixed —styles()
Enqueues styles.
public
styles() : mixed
Return values
mixed —template_loader()
Handles template usage so that we can use our own templates instead of the themes.
public
template_loader(string $template) : mixed
Templates are in the 'templates' folder. woocommerce looks for theme overides in /theme/woocommerce/ by default
For beginners, it also looks for a woocommerce.php template first. If the user adds this to the theme (containing a woocommerce() inside) this will be used for all woocommerce templates.
Parameters
- $template : string
-
Template.
Return values
mixed —update_product_query_tax_query()
Update the main product fetch query to filter by selected brands.
public
update_product_query_tax_query(array<string|int, mixed> $tax_query) : array<string|int, mixed>
Parameters
- $tax_query : array<string|int, mixed>
-
array of current taxonomy filters.
Return values
array<string|int, mixed> —wc_brands_on_block_template_register()
Add a new block to the template.
public
wc_brands_on_block_template_register(string $template_id, string $template_area, BlockTemplateInterface $template) : mixed
Parameters
- $template_id : string
-
Template ID.
- $template_area : string
-
Template area.
- $template : BlockTemplateInterface
-
Template instance.
Return values
mixed —woocommerce_brands_update_layered_nav_link()
Injects Brands filters into layered nav links.
public
woocommerce_brands_update_layered_nav_link(string $term_html, mixed $term, string $link, number $count) : string
Parameters
- $term_html : string
-
Original link html.
- $term : mixed
-
Term that is currently added.
- $link : string
-
Original layered nav item link.
- $count : number
-
Number of items in that filter.
Tags
Return values
string — Term html.get_brand_name_first_character()
Get the first letter of the brand name, returning lowercase and without accents.
private
get_brand_name_first_character(string $name) : string
Parameters
- $name : string
Tags
Return values
string —remove_terms_with_empty_products()
Remove terms with empty products.
private
remove_terms_with_empty_products(array<string|int, WP_Term> $terms) : array<string|int, WP_Term>
Parameters
- $terms : array<string|int, WP_Term>
-
The terms array that needs to be removed of empty products.
Return values
array<string|int, WP_Term> —template_already_has_brand_block()
Check if the template already contains a product brand block.
private
template_already_has_brand_block(WP_Block_Template $template) : bool
Parameters
- $template : WP_Block_Template
-
The template object.