action( 'woocommerce_no_products_found' ); } /** * Hook: woocommerce_after_main_content * * Called after rendering the main content for a product. * * @see woocommerce_output_content_wrapper_end() Outputs closing DIV for the content (priority 10) * * @since 6.3.0 */ do_action( 'woocommerce_after_main_content' ); wp_reset_postdata(); return ob_get_clean(); } /** * Get HTML markup with the right classes by attributes. * This function appends the classname at the first element that have the class attribute. * Based on the experience, all the wrapper elements have a class attribute. * * @param string $content Block content. * @param array $block Parsed block data. * @return string Rendered block type output. */ public function add_alignment_class_to_wrapper( string $content, array $block ) { if ( ( 'woocommerce/' . $this->block_name ) !== $block['blockName'] ) { return $content; } $attributes = (array) $block['attrs']; // Set the default alignment to wide. if ( ! isset( $attributes['align'] ) ) { $attributes['align'] = 'wide'; } $align_class_and_style = StyleAttributesUtils::get_align_class_and_style( $attributes ); if ( ! isset( $align_class_and_style['class'] ) ) { return $content; } // Find the first tag. $first_tag = '<[^<>]+>'; $matches = array(); preg_match( $first_tag, $content, $matches ); // If there is a tag, but it doesn't have a class attribute, add the class attribute. if ( isset( $matches[0] ) && strpos( $matches[0], ' class=' ) === false ) { $pattern_before_tag_closing = '/.+?(?=>)/'; return preg_replace( $pattern_before_tag_closing, '$0 class="' . $align_class_and_style['class'] . '"', $content, 1 ); } // If there is a tag, and it has a class already, add the class attribute. $pattern_get_class = '/(?<=class=\"|\')[^"|\']+(?=\"|\')/'; return preg_replace( $pattern_get_class, '$0 ' . $align_class_and_style['class'], $content, 1 ); } /** * Filter products by stock status when as query param there is "filter_stock_status" * * @param array $meta_query Meta query. * @return array */ public function filter_products_by_stock( $meta_query ) { global $wp_query; if ( is_admin() || ! $wp_query->is_main_query() || ! isset( $_GET[ self::FILTER_PRODUCTS_BY_STOCK_QUERY_PARAM ] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended ) { return $meta_query; } $stock_status = array_keys( wc_get_product_stock_status_options() ); $values = sanitize_text_field( wp_unslash( $_GET[ self::FILTER_PRODUCTS_BY_STOCK_QUERY_PARAM ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $values_to_array = explode( ',', $values ); $filtered_values = array_filter( $values_to_array, function( $value ) use ( $stock_status ) { return in_array( $value, $stock_status, true ); } ); if ( ! empty( $filtered_values ) ) { $meta_query[] = array( 'key' => '_stock_status', 'value' => $filtered_values, 'compare' => 'IN', ); } return $meta_query; } /** * Get the frontend style handle for this block type. * * @return null */ protected function get_block_type_style() { return null; } }