Automattic\WooCommerce\Blocks\BlockTypes
FeaturedCategory::resolve_category_id
Resolve the selected or inherited product category ID.
Method of the class: FeaturedCategory{}
No Hooks.
Returns
int.
Usage
$result = FeaturedCategory::resolve_category_id( $attributes, $context ): int;
- $attributes(array) (required)
- Block attributes.
- $context(array) (required)
- Block context.
FeaturedCategory::resolve_category_id() FeaturedCategory::resolve category id code WC 11.3.0
private static function resolve_category_id( array $attributes, array $context ): int {
if ( ! empty( $attributes['categoryId'] ) ) {
return absint( $attributes['categoryId'] );
}
$taxonomy = $context['termTaxonomy'] ?? $context['taxonomy'] ?? '';
return 'product_cat' === $taxonomy ? absint( $context['termId'] ?? 0 ) : 0;
}