Category_Protector implements Registerable, Standard_Service

This class protects categories (and their products) inside product loops, the main shop page, search results, widgets, navigation menus, and in WooCommerce shortcodes.

Adapted from WooCommerce Protected Categories.

Tags
author

Barn2 Plugins support@barn2.com

license

GPL-3.0

copyright

Barn2 Media Ltd

Interfaces, Classes and Traits

Registerable
Standard_Service

Table of Contents

$hidden_category_ids  : mixed
$unlocked_categories  : mixed
is_product_purchasable()  : bool
Determine if the product is purchasable.
protect_nav_menus()  : array<string|int, mixed>
Protect WP navigation menus.
protect_product_categories()  : array<string|int, mixed>
Protect product categories.
protect_products_in_loop()  : mixed
Protect products in the loop.
protect_products_in_shortcode()  : array<string|int, mixed>
Protect products in shortcode.
register()  : mixed
{@inheritdoc}
update_category_counts()  : array<string|int, mixed>
Update the category counts to reflect hidden ones.
build_tax_query()  : array<string|int, mixed>
Build the taxonomy query.
hidden_category_ids()  : array<string|int, mixed>
Set and retrieve hidden category ids.
unlocked_categories()  : array<string|int, mixed>
Set and retrieve unlocked category ids.

Properties

Methods

is_product_purchasable()

Determine if the product is purchasable.

public is_product_purchasable(bool $purchasable, WC_Product $product) : bool
Parameters
$purchasable : bool
$product : WC_Product
Tags
Return values
bool

protect_nav_menus()

Protect WP navigation menus.

public protect_nav_menus(array<string|int, mixed> $menu_items, string $menu, array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
$menu_items : array<string|int, mixed>
$menu : string
$args : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

protect_product_categories()

Protect product categories.

public protect_product_categories(array<string|int, mixed> $args, array<string|int, mixed> $taxonomies) : array<string|int, mixed>
Parameters
$args : array<string|int, mixed>
$taxonomies : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

protect_products_in_loop()

Protect products in the loop.

public protect_products_in_loop(WP_Query $query) : mixed
Parameters
$query : WP_Query
Tags
Return values
mixed

protect_products_in_shortcode()

Protect products in shortcode.

public protect_products_in_shortcode(array<string|int, mixed> $query_args, array<string|int, mixed> $atts[, bool|string $loop_name = false ]) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>
$atts : array<string|int, mixed>
$loop_name : bool|string = false
Tags
Return values
array<string|int, mixed>

update_category_counts()

Update the category counts to reflect hidden ones.

public update_category_counts(array<string|int, mixed> $terms, array<string|int, mixed> $taxonomies, array<string|int, mixed> $args) : array<string|int, mixed>
Parameters
$terms : array<string|int, mixed>
$taxonomies : array<string|int, mixed>
$args : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

build_tax_query()

Build the taxonomy query.

private build_tax_query(array<string|int, mixed> $query_args) : array<string|int, mixed>
Parameters
$query_args : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>

hidden_category_ids()

Set and retrieve hidden category ids.

private hidden_category_ids() : array<string|int, mixed>
Return values
array<string|int, mixed>

unlocked_categories()

Set and retrieve unlocked category ids.

private unlocked_categories() : array<string|int, mixed>
Return values
array<string|int, mixed>

Search results