$product, 'variant' => $variant, 'scope' => $scope, ]); } /** * Should this region render? * * @param string $section One of self::SECTIONS * @param array $context At minimum 'product' and 'scope'; 'variant' when * the region is variation-specific * @return bool */ public static function shouldRender($section, array $context = []) { $context = wp_parse_args($context, [ 'product' => null, 'variant' => null, 'scope' => '', ]); // Set after the merge so a caller cannot pass a 'section' that // disagrees with the hook name listeners are actually bound to. $context['section'] = $section; // Idempotent: decorate() leaves existing keys alone, so a context that // already came from self::context() is unchanged here. $context = RenderContext::decorate($context); $show = apply_filters("fluent_cart/product/show_{$section}", true, $context); return (bool) apply_filters('fluent_cart/product/show_section', $show, $context); } /** * Convenience for the two purchase buttons: the whole action row has to be * visible before an individual button inside it can be. * * Without this, hiding 'actions' would still leave a listener on * 'add_to_cart_button' able to resurrect a button into a row that is not * being rendered. * * @param string $section 'add_to_cart_button' or 'buy_now_button' * @param array $context * @return bool */ public static function shouldRenderPurchaseButton($section, array $context = []) { if (!self::shouldRender('actions', $context)) { return false; } return self::shouldRender($section, $context); } /** * CSS classes for a product card wrapper. * * @param array $classes * @param array $context * @return string Space-separated, escaped-safe class list */ public static function cardClasses(array $classes, array $context = []) { $classes = apply_filters('fluent_cart/product/card_classes', $classes, RenderContext::decorate(wp_parse_args($context, [ 'product' => null, 'scope' => self::SCOPE_CARD, ]))); if (!is_array($classes)) { return ''; } // Split on whitespace before sanitising so a listener may return either // one class per entry or a space-separated string — sanitize_html_class() // strips the space and would otherwise weld 'sale badge' into 'salebadge'. $flat = []; foreach (Arr::flatten($classes) as $class) { foreach (preg_split('/\s+/', (string) $class) as $piece) { $flat[] = $piece; } } $flat = array_filter(array_map('sanitize_html_class', $flat)); return implode(' ', array_unique($flat)); } }