function woo_ce_tags_filter_by_language() { if( !woo_ce_is_wpml_activated() ) return; $languages = ( function_exists( 'icl_get_languages' ) ? icl_get_languages( 'skip_missing=N' ) : array() ); ob_start(); ?> <p><label><input type="checkbox" id="tags-filters-language" /> <?php _e( 'Filter Tags by Language', 'woo_ce' ); ?></label></p> <div id="export-tags-filters-language" class="separator"> <ul> <li> <?php if( !empty( $languages ) ) { ?> <select data-placeholder="<?php _e( 'Choose a Language...', 'woo_ce' ); ?>" name="tag_filter_language[]" multiple class="chzn-select" style="width:95%;"> <?php foreach( $languages as $key => $language ) { ?> <option value="<?php echo $key; ?>"><?php echo $language['native_name']; ?> (<?php echo $language['translated_name']; ?>)</option> <?php } ?> </select> <?php } else { ?> <?php _e( 'No Languages were found.', 'woo_ce' ); ?></li> <?php } ?> </li> </ul> <p class="description"><?php _e( 'Select the Language\'s you want to filter exported Tags by. Default is to include all Language\'s.', 'woo_ce' ); ?></p> </div> <!-- #export-tags-filters-language --> <?php ob_end_flush(); }
function woo_ce_get_products( $args = array() ) { global $export; $limit_volume = -1; $offset = 0; $product_categories = false; $product_tags = false; $product_brands = false; $product_vendors = false; $product_status = false; $product_type = false; $product_stock = false; $product_status = false; $product_language = false; $orderby = 'ID'; $order = 'ASC'; if( $args ) { $limit_volume = ( isset( $args['limit_volume'] ) ? $args['limit_volume'] : false ); $offset = ( isset( $args['offset'] ) ? $args['offset'] : false ); if( !empty( $args['product_categories'] ) ) $product_categories = $args['product_categories']; if( !empty( $args['product_tags'] ) ) $product_tags = $args['product_tags']; if( !empty( $args['product_brands'] ) ) $product_brands = $args['product_brands']; if( !empty( $args['product_vendors'] ) ) $product_vendors = $args['product_vendors']; if( !empty( $args['product_status'] ) ) $product_status = $args['product_status']; if( !empty( $args['product_type'] ) ) $product_type = $args['product_type']; if( !empty( $args['product_stock'] ) ) $product_stock = $args['product_stock']; if( !empty( $args['product_language'] ) ) $product_language = $args['product_language']; if( isset( $args['product_orderby'] ) ) $orderby = $args['product_orderby']; if( isset( $args['product_order'] ) ) $order = $args['product_order']; } $post_type = apply_filters( 'woo_ce_get_products_post_type', array( 'product' ) ); $post_status = apply_filters( 'woo_ce_get_products_status', array( 'publish', 'pending', 'draft', 'future', 'private' ) ); $args = array( 'post_type' => $post_type, 'orderby' => $orderby, 'order' => $order, 'offset' => $offset, 'posts_per_page' => $limit_volume, 'post_status' => woo_ce_post_statuses( $post_status, true ), 'fields' => 'ids', 'suppress_filters' => false ); // Filter Products by Product Category if( $product_categories ) { $term_taxonomy = 'product_cat'; // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_categories ) ); } // Filter Products by Product Tag if( $product_tags ) { $term_taxonomy = 'product_tag'; // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_tags ) ); } // WooCommerce Brands Addon - http://woothemes.com/woocommerce/ if( $product_brands ) { $term_taxonomy = apply_filters( 'woo_ce_brand_term_taxonomy', 'product_brand' ); // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_brands ) ); } // Product Vendors - http://www.woothemes.com/products/product-vendors/ if( $product_vendors ) { $term_taxonomy = 'shop_vendor'; // Check if tax_query has been created if( !isset( $args['tax_query'] ) ) $args['tax_query'] = array(); $args['tax_query'][] = array( array( 'taxonomy' => $term_taxonomy, 'field' => 'id', 'terms' => $product_vendors ) ); } // Filter Products by Language if( $product_language ) { global $sitepress; // See if our WPML integration magic sticks remove_filter( 'posts_where' , array( $sitepress, 'posts_where_filter' ), 10 ); add_filter( 'posts_where' , 'woo_ce_wp_query_product_where_override_language' ); } // Filter Products by Post Status if( $product_status ) $args['post_status'] = woo_ce_post_statuses( $product_status, true ); // Filter Products by Product Type if( $product_type ) { // Check if we are just exporting variations if( in_array( 'variation', $product_type ) && count( $product_type ) == 1 ) $args['post_type'] = array( 'product_variation' ); $args['meta_query'] = array( 'relation' => 'OR' ); if( in_array( 'downloadable', $product_type ) ) { $args['meta_query'][] = array( 'key' => '_downloadable', 'value' => 'yes', 'compare' => 'EXISTS' ); } if( in_array( 'virtual', $product_type ) ) { $args['meta_query'][] = array( 'key' => '_virtual', 'value' => 'yes' ); } // Remove non-Term based Product Types before we tack on our tax_query $term_product_type = $product_type; foreach( $term_product_type as $key => $type ) { if( in_array( $type, array( 'downloadable', 'virtual', 'variation' ) ) ) unset( $term_product_type[$key] ); } if( !empty( $term_product_type ) ) { $args['tax_query'][] = array( array( 'taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $term_product_type ) ); } else { unset( $args['meta_query'] ); } unset( $term_product_type ); } $products = array(); // Allow other developers to bake in their own filters $args = apply_filters( 'woo_ce_get_products_args', $args ); $product_ids = new WP_Query( $args ); if( $product_ids->posts ) { foreach( $product_ids->posts as $product_id ) { $product = get_post( $product_id ); // Filter out variations that don't have a Parent Product that exists if( isset( $product->post_type ) && $product->post_type == 'product_variation' ) { // Check if Parent exists if( $product->post_parent ) { if( !get_post( $product->post_parent ) ) { unset( $product_id, $product ); continue; } } } // Filter out Products based on the Stock Status and Quantity if( $product_stock ) { $manage_stock = get_post_meta( $product_id, '_manage_stock', true ); $stock_status = get_post_meta( $product_id, '_stock_status', true ); $quantity = get_post_meta( $product_id, '_stock', true ); $quantity = ( function_exists( 'wc_stock_amount' ) ? wc_stock_amount( $quantity ) : $quantity ); switch( $product_stock ) { case 'outofstock': if( ( $manage_stock == 'yes' && $quantity > 0 ) || $stock_status <> 'outofstock' ) { unset( $product_id, $product ); continue; } break; case 'instock': if( ( $manage_stock == 'yes' && $quantity == 0 ) || $stock_status <> 'instock' ) { unset( $product_id, $product ); continue; } break; } unset( $stock_status ); } if( isset( $product_id ) ) $products[] = $product_id; // Include Variables in a new WP_Query if a tax_query filter is used or WPML exists if( isset( $args['tax_query'] ) || woo_ce_is_wpml_activated() ) { $term_taxonomy = 'product_type'; if( has_term( 'variable', $term_taxonomy, $product_id ) && ( $product_type !== false && in_array( 'variation', $product_type ) ) ) { $variable_args = array( 'post_type' => 'product_variation', 'orderby' => $orderby, 'order' => $order, 'post_parent' => $product_id, 'post_status' => array( 'publish' ), 'fields' => 'ids' ); $variables = array(); $variable_ids = new WP_Query( $variable_args ); if( $variable_ids->posts ) { foreach( $variable_ids->posts as $variable_id ) { // Check we're not including a duplicate Product ID if( !in_array( $variable_id, $product_ids->posts ) ) $products[] = $variable_id; } } unset( $variables, $variable_ids, $variable_args, $variable_id ); } } } // Check if the global $export has been created if( isset( $export ) ) $export->total_rows = count( $products ); unset( $product_ids, $product_id ); } // Filter Products by Language if( $product_language ) { global $sitepress; add_filter( 'posts_where' , array( $sitepress, 'posts_where_filter' ), 10, 2 ); remove_filter( 'posts_where' , 'woo_ce_wp_query_product_where_override_language' ); } return $products; }