Ids = apply_filters( 'dgwt/wcas/search_page/result_post_ids', array() ); if ( $searchIds && is_array( $searchIds ) ) { $postIds = isset( $args['post__in'] ) ? $args['post__in'] : ''; if ( is_array( $postIds ) && ! empty( $postIds ) ) { if ( 1 !== count( $postIds ) || 0 !== $postIds[0] ) { $args['post__in'] = array_intersect( $postIds, $searchIds ); } } else { $args['post__in'] = $searchIds; } $args['s'] = ''; } } if ( ! empty( $args['post__in'] ) && ( 'product' === $args['post_type'] ) ) { $args['post_type'] = array( 'product', 'product_variation' ); } $args = $this->addWooOptions( $args ); foreach ( $param['generalSettings'] as $filter ) { $settings = ( isset( $filter['settings'] ) ) ? $filter['settings'] : []; $hiddens = array( 'f_hidden_brands', 'f_hidden_categories', 'f_hidden_attributes', 'f_hidden_tags' ); $replace = false; foreach ( $hiddens as $hidden ) { if ( $this->getFilterSetting( $settings, $hidden ) ) { $replace = true; } } if ( $replace ) { foreach ( $args['tax_query'] as &$tax ) { if ( isset ( $tax['wpf_group'] ) && $tax['wpf_group'] === $filter['name'] && isset( $tax[0]['terms'] ) ) { $tax[0]['terms'] = $settings['f_mlist[]']; } } } } return DispatcherWpf::applyFilters( 'addFilterExistsItemsArgs', $args ); } /** * Returns items in filter blocks * * @param $filterLoop * @param $param * * @return array */ public function getTerms( $listTable, $param ) { $calcCategories = array(); $childs = array(); $names = array(); $colorGroup = array(); $addSqls = array(); $curSettings = ( isset($param['currentSettings']) ? $param['currentSettings'] : array() ); $byVariations = ( !empty($curSettings['filtering_by_variations']) && !empty($curSettings['form_filter_by_variations']) ); $customPrefixes = DispatcherWpf::applyFilters( 'getCustomPrefixes', array(), false ); if ( empty( $customPrefixes ) ) { $taxonomyList = $param['taxonomy']; } else { $taxonomyList = array(); foreach ( $param['taxonomy'] as $i => $tax ) { $pos = strpos( $tax, '-' ); if ( ! $pos || ! in_array( substr( $tax, 0, $pos + 1 ), $customPrefixes, true ) ) { $taxonomyList[] = $tax; } } } global $wpdb; $sql = array(); $stockJoin = ''; if ($param['isInStockOnly']) { $metaKeyId = $this->getMetaKeyId('_stock_status'); if ($metaKeyId) { $valueId = FrameWpf::_()->getModule('meta')->getModel('meta_values')->getMetaValueId($metaKeyId, 'outofstock'); $stockJoin = ' INNER JOIN @__meta_data pm ON (pm.product_id=wpf_temp.ID AND pm.key_id=' . $metaKeyId . ' AND pm.val_id!=' . $valueId . ')'; } else { $stockJoin = ' INNER JOIN ' . $wpdb->postmeta . " pm ON (pm.post_id=wpf_temp.ID AND pm.meta_key='_stock_status' AND pm.meta_value!='outofstock')"; } } if ( ! empty( $taxonomyList ) ) { $addSqls['main']['withCount'] = $param['withCount']; $addSqls['main']['fields'] = ( $param['withCount'] ? '' : 'DISTINCT ' ) . 'tr.term_taxonomy_id, tt.term_id, tt.taxonomy, tt.parent' . ( $param['withCount'] ? ', COUNT(*) as cnt' : '' ); $addSqls['main']['taxonomyList'] = implode( "', '", $taxonomyList ); if ($byVariations) { $attrTaxonomyList = array(); $case = ''; $mainAttrId = $this->getMetaKeyId('_product_attributes'); if ($mainAttrId) { foreach ($taxonomyList as $tax) { if (strpos($tax, 'pa_') === 0) { $metaKeyId = $this->getMetaKeyId('attribute_' . $tax); if ($metaKeyId) { $isForVars = FrameWpf::_()->getModule( 'meta' )->getModel( 'meta_values' )->getMetaValueId($mainAttrId, '1', array('key2' => 'is_variation', 'key3' => $tax)); if ($isForVars) { $attrTaxonomyList[$tax] = $metaKeyId; $case .= ' WHEN md_attr.key_id=' . $metaKeyId . " THEN '" . $tax . "'"; } } } } } if (!empty($attrTaxonomyList)) { //$query = 'SELECT wpf_temp.id, p_vars.id as child, md_vals.value, (CASE ' . $case . " ELSE '' END) as taxonomy" . $query = "SELECT wpf_temp.id, p_vars.id as child, md_vals.value, REPLACE(md_keys.meta_key, 'attribute_', '') as taxonomy" . ' FROM ' . $listTable . ' as wpf_temp' . ' INNER JOIN #__posts as p_vars on (p_vars.post_parent=wpf_temp.id)' . ' INNER JOIN @__meta_data as md_attr ON (md_attr.product_id=p_vars.ID AND md_attr.key_id IN (' . implode(',', $attrTaxonomyList) . '))' . ' INNER JOIN @__meta_values as md_vals ON (md_vals.id=md_attr.val_id)' . ' INNER JOIN @__meta_keys as md_keys ON (md_keys.id=md_attr.key_id)' . str_replace('wpf_temp.', 'p_vars.', $stockJoin); $listVariationAttributes = $this->createTemporaryTable($this->tempFilterTable . '_var_attrs', $query); $typeJoin = ''; $metaKeyId = $this->getMetaKeyId('_wpf_product_type'); if ($metaKeyId) { $variableMetaId = FrameWpf::_()->getModule('meta')->getModel('meta_values')->getMetaValueId($metaKeyId, 'variable'); if ($variableMetaId) { $typeJoin = ' INNER JOIN @__meta_data md_type ON (md_type.product_id=wpf_temp.ID AND md_type.key_id=' . $metaKeyId . ')'; } } if (empty($typeJoin)) { $byVariations = false; } } else { $byVariations = false; } } } $taxonomyList = array(); $colorGroup = DispatcherWpf::applyFilters( 'getColorGroupForExistTerms', array(), $param ); if ( ! empty( $colorGroup ) ) { foreach ( $param['taxonomy'] as $key => $tax ) { if ( key_exists( $tax, $colorGroup ) ) { unset( $param['taxonomy'][ $key ] ); $taxonomyList[] = $tax; } } $addSqls['color']['withCount'] = false; $addSqls['color']['fields'] = 'tt.term_id, tt.taxonomy, wpf_temp.ID'; $addSqls['color']['taxonomyList'] = implode( "', '", $taxonomyList ); } foreach ( $addSqls as $key => $addSql ) { $sql[ $key ] = 'SELECT ' . $addSql['fields'] . ' FROM ' . $listTable . ' AS wpf_temp INNER JOIN ' . $wpdb->term_relationships . ' tr ON (tr.object_id=wpf_temp.ID) INNER JOIN ' . $wpdb->term_taxonomy . ' tt ON (tt.term_taxonomy_id=tr.term_taxonomy_id) '; /*if ( $addSql['withCount'] && $param['isInStockOnly'] ) { $metaKeyId = $this->getMetaKeyId( '_stock_status' ); if ( $metaKeyId ) { $valueId = FrameWpf::_()->getModule( 'meta' )->getModel( 'meta_values' )->getMetaValueId( $metaKeyId, 'outofstock' ); $sql[ $key ] .= ' INNER JOIN @__meta_data pm ON (pm.product_id=wpf_temp.ID AND pm.key_id=' . $metaKeyId . ' AND pm.val_id!=' . $valueId . ')'; } else { $sql[ $key ] .= ' INNER JOIN ' . $wpdb->postmeta . " pm ON (pm.post_id=wpf_temp.ID AND pm.meta_key='_stock_status' AND pm.meta_value!='outofstock')"; } }*/ if ( $addSql['withCount'] && $param['isInStockOnly'] ) { $sql[ $key ] .= $stockJoin; } if ($byVariations) { $sql[ $key ] .= ' INNER JOIN ' . $wpdb->terms . ' ttt ON (ttt.term_id=tt.term_id) ' . $typeJoin; } $sql[ $key ] .= ' WHERE tt.taxonomy IN (\'' . $addSql['taxonomyList'] . '\')'; if ($byVariations) { $sql[ $key ] .= ' AND (md_type.val_id!=' . $variableMetaId . ' OR tt.taxonomy NOT IN (\'' . implode("','", array_keys($attrTaxonomyList)) . '\')' . ' OR EXISTS(SELECT 1 FROM ' . $listVariationAttributes . ' as p_childs' . ' WHERE p_childs.id=wpf_temp.id and p_childs.taxonomy=tt.taxonomy and p_childs.value=ttt.slug LIMIT 1))'; } if ( $addSql['withCount'] ) { $sql[ $key ] .= ' GROUP BY tr.term_taxonomy_id'; } } if ( FrameWpf::_()->proVersionCompare( WPF_PRO_REQUIRES, '>=' ) ) { //$termProducts = DbWpf::get( $sql ); $termProducts = ! isset( $sql['main'] ) ? array() : DbWpf::get( $sql['main'] ); if ( false === $termProducts ) { $termProducts = array(); } $termProducts = DispatcherWpf::applyFilters( 'addCustomAttributesSql', $termProducts, array( 'taxonomies' => $param['taxonomy'], 'withCount' => $param['withCount'], 'listTable' => $listTable, 'generalSettings' => $param['generalSettings'], 'currentSettings' => $param['currentSettings'] ) ); } else { $sql['main'] = DispatcherWpf::applyFilters( 'addCustomAttributesSql', $sql['main'], array( 'taxonomies' => $param['taxonomy'], 'withCount' => $param['withCount'], 'productList' => '(select id from ' . $listTable . ')', 'generalSettings' => $param['generalSettings'], 'currentSettings' => $param['currentSettings'] ) ); $wpdb->wpf_prepared_query = $sql['main']; $termProducts = $wpdb->get_results( $wpdb->wpf_prepared_query ); } $existTerms = array(); foreach ( $termProducts as $term ) { $taxonomy = $term['taxonomy']; $isCat = 'product_cat' === $taxonomy; $name = urldecode( $taxonomy ); $names[ $name ] = $taxonomy; if ( ! isset( $existTerms[ $name ] ) ) { $existTerms[ $name ] = array(); } $termId = $term['term_id']; if ( $isCat && isset( $param['only_children_category'] ) && ! in_array( (int) $termId, $param['only_children_category'], true ) ) { continue; } if ( $isCat && !empty( $param['onlyCategories'] ) ) { $found = true; foreach ($param['onlyCategories'] as $catIds) { if (!in_array( (int) $termId, $catIds, true ) ) { $found = false; break; } } if (!$found) { continue; } } $cnt = $param['withCount'] ? intval( $term['cnt'] ) : 0; $existTerms[ $name ][ $termId ] = $cnt; $parent = ( isset( $term['parent'] ) ) ? (int) $term['parent'] : 0; if ( $isCat && $param['isCalcCategory'] && $param['calcCategory'] === $parent ) { $calcCategories[ $termId ] = $cnt; } if ( 0 !== $parent ) { $children = array( $termId ); do { if ( ! isset( $existTerms[ $name ][ $parent ] ) ) { $existTerms[ $name ][ $parent ] = 0; } if ( isset( $childs[ $parent ] ) ) { array_merge( $childs[ $parent ], $children ); } else { $childs[ $parent ] = $children; } $parentTerm = get_term( $parent, $taxonomy ); $children[] = $parent; if ( $parentTerm && isset( $parentTerm->parent ) ) { $parent = $parentTerm->parent; if ( $isCat && $param['isCalcCategory'] && $param['calcCategory'] === $parent ) { $calcCategories[ $parentTerm->term_id ] = 0; } } else { $parent = 0; } } while ( 0 !== $parent ); } } if ( 'light' !== $param['mode'] && $param['withCount'] ) { foreach ( $existTerms as $taxonomy => $terms ) { $allCalc = in_array( $taxonomy, $param['forCount'], true ); $calcWithChildren = in_array( $taxonomy, $param['forCountWithChildren'], true ); if ( ! ( $allCalc || ( $param['isCalcCategory'] && 'product_cat' === $taxonomy ) || $calcWithChildren ) ) { continue; } foreach ( $terms as $termId => $cnt ) { if ( $calcWithChildren ) { $termIds = get_term_children( $termId, $names[ $taxonomy ] ); } else { if ( isset( $childs[ $termId ] ) && ( $allCalc || isset( $calcCategories[ $termId ] ) ) ) { $termIds = $childs[ $termId ]; } else { continue; } } $termIds[] = $termId; $sqlTemp = "SELECT count(DISTINCT tr.`object_id`) FROM {$listTable} AS wpf_temp INNER JOIN {$wpdb->term_relationships} AS tr ON (tr.`object_id`=wpf_temp.`ID`) INNER JOIN {$wpdb->term_taxonomy} AS wtf ON tr.`term_taxonomy_id` = wtf.`term_taxonomy_id` WHERE wtf.`term_id` IN (" . implode( ',', $termIds ) . ')'; $cnt = intval( DbWpf::get( $sqlTemp, 'one' ) ); $existTerms[ $taxonomy ][ $termId ] = $cnt; if ( isset( $calcCategories[ $termId ] ) ) { $calcCategories[ $termId ] = $cnt; } } } } if ( ! empty( $colorGroup ) && isset( $sql['color'] ) ) { $termProducts = DbWpf::get( $sql['color'] ); $existTerms = DispatcherWpf::applyFilters( 'getExistTermsColor', $existTerms, $colorGroup, $termProducts ); } return array( $existTerms, $calcCategories ); } /** * Returns additional data on minimum and maximum prices and users * * @param $args * @param $param * * @return mixed */ public function getExistsMore( $args, $param, $result ) { global $wpdb; if (!isset($result['existsPrices'])) { $result['existsPrices'] = new stdClass(); $result['existsPrices']->wpfMinPrice = 1000000000; $result['existsPrices']->wpfMaxPrice = 0; $result['existsPrices']->decimal = 0; $result['existsPrices']->dataStep = '1'; $result['existsUsers'] = array(); } $listTable = $param['listTable']; $mode = $param['calcMode']; $need = ( 'full' === $mode && !key_exists('light', $param['calcVars']) ) || 'light' === $mode; if ( $param['havePosts'] && ! empty ( $param['taxonomies']['other_names'] ) ) { foreach ( $param['generalSettings'] as $setting ) { if ( ! isset( $setting['id'] ) ) { continue; } if ( in_array( $setting['id'], $param['taxonomies']['other_names'], true ) ) { if ('wpfPrice' == $setting['id']) { $keep = $param['taxonomies']['keep_recount_price']; if ( ( !$keep && !$need ) || ( $keep && 'full' != $mode ) ) { continue; } } else if (!$need) { continue; } switch ( $setting['id'] ) { case 'wpfPrice': case 'wpfPriceRange': $listTableForPrice = $listTable; if ( isset( $args['meta_query'] ) && is_array( $args['meta_query'] ) ) { $issetArgsPrice = false; foreach ( $args['meta_query'] as $key => $row ) { if ( isset( $row['price_filter'] ) ) { $issetArgsPrice = true; unset ( $args['meta_query'][ $key ] ); } } if ( $issetArgsPrice ) { $filterLoop = new WP_Query( $args ); if ( $filterLoop->have_posts() ) { $listTableForPrice = $this->createTemporaryTable( $this->tempFilterTable . '_price', $filterLoop->request ); } } } list( $result['existsPrices']->decimal, $result['existsPrices']->dataStep ) = DispatcherWpf::applyFilters( 'getDecimal', array( 0, 1 ), $setting['settings'] ); if ( 'wpfPriceRange' === $setting['id'] ) { $price = $this->getView()->wpfGetFilteredPriceFromProductList( $setting['settings'], $listTableForPrice, false, $result['existsPrices']->decimal ); } else { $price = $this->getView()->wpfGetFilteredPriceFromProductList( $setting['settings'], $listTableForPrice, true, $result['existsPrices']->decimal ); } if ( is_object( $price ) ) { $result['existsPrices']->wpfMinPrice = $price->wpfMinPrice; $result['existsPrices']->wpfMaxPrice = $price->wpfMaxPrice; if ( isset( $price->tax ) ) { $result['existsPrices']->tax = $price->tax; } } break; case 'wpfAuthor': case 'wpfVendors': if ( empty( $result['existsUsers'] ) ) { $query = 'SELECT DISTINCT ' . $wpdb->users . '.ID' . ' FROM ' . $listTable . ' AS wpf_temp' . ' INNER JOIN ' . $wpdb->posts . ' p ON (p.ID=wpf_temp.ID)' . ' JOIN ' . $wpdb->users . ' ON p.post_author = ' . $wpdb->users . '.ID'; $result['existsUsers'] = dbWpf::get( $query ); } break; case 'wpfAttribute': if ( false === $param['ajax'] ) { $frontendType = $this->getFilterSetting( $setting['settings'], 'f_frontend_type', '' ); if ( 'slider' === $frontendType ) { $showAllSliderAttributes = $this->getFilterSetting( $setting['settings'], 'f_show_all_slider_attributes', false ); if ( $showAllSliderAttributes ) { $this->clauses = array(); $name = $setting['name']; $data = ReqWpf::get( 'get' ); unset( $data[ $name ] ); $args['meta_query'] = DispatcherWpf::applyFilters( 'addCustomMetaQueryPro', $args['meta_query'], $data, 'url' ); $filterLoop = new WP_Query( $args ); if ( $filterLoop->have_posts() ) { $listTable = $this->createTemporaryTable( $this->tempFilterTable . '_attribute', $filterLoop->request ); if ( ! empty( $listTable ) ) { list( $existsTerms, $calcCategories ) = $this->getTerms( $listTable, $param, $result['exists'] ); $customPrefixes = DispatcherWpf::applyFilters( 'getCustomPrefixes', array(), false ); foreach ( $customPrefixes as $prefix ) { if ( strpos( $name, $prefix ) === 0 ) { $name = str_replace( $prefix, '', $name ); } } if ( isset( $existsTerms[ $name ] ) ) { $result['exists'][ $name ] = $existsTerms[ $name ]; } } } } } } break; } } } } return $result; } public function addAjaxFilterForYithWoocompare( $actions ) { return array_merge( $actions, array( 'filtersFrontend' ) ); } public function getAllPages() { global $wpdb; $allPages = dbWpf::get( "SELECT ID, post_title FROM $wpdb->posts WHERE post_type = 'page' AND post_status IN ('publish','draft') ORDER BY post_title" ); $pages = array(); if ( ! empty( $allPages ) ) { foreach ( $allPages as $p ) { $pages[ $p['ID'] ] = $p['post_title']; } } return $pages; } public function isWcVendorsPluginActivated() { return class_exists( 'WC_Vendors' ); } /** * Get logic for filtering. * * @return array */ public function getAttrFilterLogic( $mode = '' ) { $logic = array( 'display' => array( 'and' => 'And', 'or' => 'Or', ), 'loop' => array( 'and' => 'AND', 'or' => 'IN', ), 'delimetr' => array( 'and' => ',', 'or' => '|', ) ); $logic = DispatcherWpf::applyFilters( 'getAttrFilterLogic', $logic ); return empty( $mode ) ? $logic : ( isset( $logic[ $mode ] ) ? $logic[ $mode ] : array() ); } public function getFilterTagsList() { return array( 0 => 'Default', 1 => 'h1', 2 => 'h2', 3 => 'h3', 4 => 'h4', 5 => 'h5' ); } public function getCategoriesDisplay( $tax = 'product_cat' ) { $catArgs = array( 'taxonomy' => $tax, 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => false, ); $productCategories = get_terms( $catArgs ); $categoryDisplay = array(); $parentCategories = array(); if (is_array($productCategories)) { foreach ( $productCategories as $c ) { if ( 0 == $c->parent ) { array_push( $parentCategories, $c->term_id ); } $categoryDisplay[ $c->term_id ] = '[' . $c->term_id . '] ' . $c->name; } } return array( $categoryDisplay, $parentCategories ); } public function getTagsDisplay() { $tagArgs = array( 'taxonomy' => 'product_tag', 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => false, 'parent' => 0 ); $productTags = get_terms( $tagArgs ); $tagsDisplay = array(); if ( is_array( $productTags ) ) { foreach ( $productTags as $t ) { $tagsDisplay[ $t->term_id ] = $t->name; } } return array( $tagsDisplay ); } public function getAttributesDisplay( $withCustom = true ) { $productAttr = function_exists('wc_get_attribute_taxonomies') ? wc_get_attribute_taxonomies() : array(); if ($withCustom) { $productAttr = DispatcherWpf::applyFilters( 'addCustomAttributes', $productAttr ); } $attrDisplay = array( 0 => esc_html__( 'Select...', 'woo-product-filter' ) ); $attrTypes = array(); $attrNames = array(); foreach ( $productAttr as $attr ) { $attrId = (int) $attr->attribute_id; $slug = empty( $attrId ) ? $attr->attribute_slug : $attrId; $attrDisplay[ $slug ] = $attr->attribute_label; $attrTypes[ $slug ] = isset( $attr->custom_type ) ? $attr->custom_type : ''; $attrNames[ $slug ] = isset( $attr->filter_name ) ? $attr->filter_name : 'wpf_filter_' . $attr->attribute_name; } return array( $attrDisplay, $attrTypes, $attrNames ); } public function getRolesDisplay() { if ( ! function_exists( 'get_editable_roles' ) ) { require_once ABSPATH . '/wp-admin/includes/user.php'; } $rolesMain = get_editable_roles(); $roles = array(); foreach ( $rolesMain as $key => $r ) { $roles[ $key ] = $r['name']; } return array( $roles ); } /** * Exlude parent terms from term list * * @param array $termList * @param string $taxonomy * * @return array */ public function exludeParentTems( $termList, $taxonomy ) { foreach ( $termList as $key => $termId ) { $parents = get_ancestors( $termId, $taxonomy, 'taxonomy' ); if ( is_array( $parents ) ) { // remove all parent termsId from main parent list foreach ( $parents as $parentId ) { if ( array_search( $parentId, $termList ) !== false ) { $keyParent = array_search( $parentId, $termList ); unset( $termList[ $keyParent ] ); } } } } return $termList; } /** * Exlude parent terms from term list * * @param array $termList * @param string $taxonomy * * @return array */ public function exludeChildTems( $termList, $taxonomy ) { foreach ( $termList as $key => $termId ) { $children = get_term_children( $termId, $taxonomy ); if ( is_array( $children ) ) { // remove all parent termsId from main parent list foreach ( $children as $childId ) { if ( array_search( $childId, $termList ) !== false ) { $keyParent = array_search( $childId, $termList ); unset( $termList[ $keyParent ] ); } } } } return $termList; } /** * Add shortcode attributes to additional html data attributes * * @param array $attributes */ public function addWoocommerceShortcodeQuerySettings( $attributes ) { $shortcodeAttr = htmlentities( UtilsWpf::jsonEncode( $attributes ), ENT_COMPAT ); echo ''; } public static function getProductsShortcode( $content ) { $shortcode_tags = array( 'products' => 'WC_Shortcodes::products', 'sale_products' => 'WC_Shortcodes::sale_products', ); $original = $content; if (empty($content)) { $id = get_the_ID(); if ($id) { $p = get_post($id); if ($p) { $content = $p->post_content; } } } if ( false === strpos( $content, '[' ) ) { return $original; } if ( empty( $shortcode_tags ) || ! is_array( $shortcode_tags ) ) { return $original; } preg_match_all( '@\[([^<>&/\[\]\x00-\x20=]++)@', $content, $matches ); $tagnames = array_intersect( array_keys( $shortcode_tags ), $matches[1] ); if ( empty( $tagnames ) ) { // some themes hide woocommerce shortcodes inside their shortcodes, // so there is nothing left to do but let them run for execution $theme = wp_get_theme(); if ( $theme instanceof WP_Theme ) { $themeName = ( '' !== $theme['Parent Theme'] ) ? $theme['Parent Theme'] : $theme['Name']; if ( 'Divi' === $themeName ) { //add_filter( 'pre_do_shortcode_tag', array( 'WoofiltersWpf', 'getOtherShortcodeAttr' ), 10, 3 ); add_filter( 'pre_do_shortcode_tag', function ( $return, $tag, $attr ) { if ( 'et_pb_shop' === $tag ) { if ( isset( $attr['module_class'] ) && '' !== $attr['module_class'] ) { self::$otherShortcodeAttr['class'] = $attr['module_class']; } else { unset( self::$otherShortcodeAttr['class'] ); } } return $return; }, 10, 3 ); preg_match_all( '@(\[et_pb_shop.*?\/et_pb_shop\])@', $content, $diviShortCodes ); if ( isset( $diviShortCodes[1] ) ) { foreach ( $diviShortCodes[1] as $diviShortCode ) { do_shortcode( $diviShortCode ); } } } else if ('Shoptimizer' === $themeName) { preg_match_all( '@(\[elementor-template.*?\])@', $content, $elementorTemplates ); if ( isset( $elementorTemplates[1] ) ) { foreach ( $elementorTemplates[1] as $elementorTemplate) { do_shortcode( $elementorTemplate); } } } } return $original; } $pattern = get_shortcode_regex( $tagnames ); preg_match_all( "/$pattern/", $content, $matches ); if ( count( $matches ) > 3 ) { foreach ( (array) $matches[3] as $key => $m ) { if ( 'sale_products' === $matches[2][ $key ] ) { $m .= ' on_sale="true"'; } new WC_Shortcode_Products( shortcode_parse_atts( $m ), 'products' ); } } return $original; } public function queryResults( $result ) { if ( 0 === $result->total ) { $options = FrameWpf::_()->getModule( 'options' )->getModel( 'options' )->getAll(); if ( isset( $options['not_found_products_message'] ) && '1' === $options['not_found_products_message']['value'] ) { echo '
' . esc_html__( 'No products were found matching your selection.', 'woocommerce' ) . '
'; } } return $result; } public function getElementorClass( $data ) { $rawData = $data->get_raw_data(); if ( isset( $rawData['settings']['_css_classes'] ) && '' !== $rawData['settings']['_css_classes'] ) { self::$currentElementorClass = $rawData['settings']['_css_classes']; } } public function shortcodeAttsProducts( $out, $pairs, $atts ) { if ( isset( $atts['on_sale'] ) && ! isset( $out['on_sale'] ) ) { $out['on_sale'] = $atts['on_sale']; } $out['cache'] = false; return $out; } public function addWpfMetaClauses( $params ) { if ( empty( $params['values'] || $params['keyId'] ) ) { return; } global $wpdb; $isLight = empty( $params['isLight'] ) ? false : $params['isLight']; $isAnd = isset( $params['isAnd'] ) && true === $params['isAnd']; $isBetween = isset( $params['isAnd'] ) && 'BETWEEN' === $params['isAnd']; $keyId = $params['keyId']; $field = empty( $params['field'] ) ? 'id' : $params['field']; $values = UtilsWpf::controlNumericValues( $params['values'], $field ); $i = 0; $clauses = array( 'join' => array(), 'where' => array() ); if (empty($params['searchLogic'])) { foreach ( $values as $val ) { $i ++; $clauses['join'][ $i ] = ' INNER JOIN ' . DbWpf::getTableName( 'meta_data' ) . ' AS wpf_meta__#i ON (wpf_meta__#i.product_id=' . $wpdb->posts . '.ID AND wpf_meta__#i.key_id' . ( is_array( $keyId ) ? ' IN (' . implode( ',', $keyId ) . ')' : '=' . $keyId ) . ')'; $clauses['where'][$i] = ' AND wpf_meta__#i.val_' . $field . ( $isAnd ? '=' . $val : ( $isBetween ? ' BETWEEN ' . ( empty( $values[0] ) ? 0 : $values[0] ) . ' AND ' . ( empty( $values[1] ) ? 0 : $values[1] ) : ' IN (' . implode( ',', $values ) . ')' ) ); if ( ! $isAnd ) { break; } } } else { $i ++; $keyDec = !empty($params['keyName']) && $this->getMetaKeyId($params['keyName'], 'meta_type') == 1; $clauses['join'][ $i ] = ' INNER JOIN ' . DbWpf::getTableName( 'meta_data' ) . ' AS wpf_meta__#i ON (wpf_meta__#i.product_id=' . $wpdb->posts . '.ID AND wpf_meta__#i.key_id' . ( is_array( $keyId ) ? ' IN (' . implode( ',', $keyId ) . ')' : '=' . $keyId ) . ')'; if ($keyDec) { $clauses['where'][$i] = ' AND wpf_meta__#i.val_dec' . $params['searchLogic'] . $params['values'][0]; } else { $clauses['join'][ $i ] .= ' INNER JOIN ' . DbWpf::getTableName( 'meta_values' ) . ' AS wpf_meta_values__#i ON (wpf_meta_values__#i.id=wpf_meta__#i.val_id)'; $clauses['where'][$i] = ' AND wpf_meta_values__#i.value+0' . $params['searchLogic'] . $params['values'][0]; } } $this->addFilterClauses( $clauses, $isLight, $params['urlParam'] ); return; } public function getOtherShortcodeAttr( $return, $tag, $attr ) { if ( 'et_pb_shop' === $tag ) { if ( isset( $attr['module_class'] ) && '' !== $attr['module_class'] ) { self::$otherShortcodeAttr['class'] = $attr['module_class']; } else { unset( self::$otherShortcodeAttr['class'] ); } } return $return; } public function getFilterLoopFromMode( $mode, $args ) { $clauses = $this->clauses; if ( 'full' === $mode ) { foreach ( $this->clausesByParam as $mode => $clausesMode ) { if ( 'variation' !== $mode ) { foreach ( $clausesMode as $key => $clausesRemove ) { if ( isset( $this->clauses[ $key ] ) ) { $this->clauses[ $key ] = array_diff( $this->clauses[ $key ], $clausesRemove ); } } } } } elseif ( isset( $this->clausesByParam[ $mode ] ) ) { foreach ( $this->clausesByParam[ $mode ] as $key => $clausesRemove ) { if ( isset( $this->clauses[ $key ] ) ) { $this->clauses[ $key ] = array_diff( $this->clauses[ $key ], $clausesRemove ); } } } $filterLoop = new WP_Query( $args ); $this->clauses = $clauses; return $filterLoop; } public function getTaxonomyByUrl( $param ) { $taxonomy = null; $param = preg_replace( '/(_\d+)$/', '', $param ); if ( 0 === strpos( $param, 'wpf_filter_cat_' ) ) { $taxonomy = 'product_cat'; } elseif ( 0 === strpos( $param, 'product_tag_' ) ) { $taxonomy = 'product_tag'; } elseif ( 0 === strpos( $param, 'wpf_filter_pwb.' ) ) { $taxonomy = 'pwb-brand'; } elseif ( 0 === strpos( $param, 'fmeta-' ) ) { $taxonomy = $param; } elseif ( 0 === strpos( $param, 'wpf_filter_' ) ) { $taxonomy = preg_replace( '/^wpf_filter_/', 'pa_', $param ); } return $taxonomy; } public function getDefaultSettings() { $defaults = array( 'force_theme_templates' => '' ); return DispatcherWpf::applyFilters('getDefaultSettings', $defaults); } }