Home Forums WoodMart support forum Products with NEW label and hiding out of stock products

Products with NEW label and hiding out of stock products

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #52038

    Hello, I have set some products with the NEW label. I also have set the woocommerce built-in function to hide products that are out of stock. The result is that the home page widget is keeping occupied a product widget by a product that is not apparent. You can check my site that there is one product missing but if you click the right arrow you can find some other products with the new label. Can you please fix that?
    Secondly i would like to find an easy way to search the products that i ahve set with NEW label and to change it. Because right now i can’t find what was the product that is out of stock and is not displaying. The only solution is to disable hide out of stock products from woocommerce and then back again.
    Thank you in advance.

    #52073

    Artem Temos
    Keymaster

    Hello,

    Does it happen on the home page only? Is it work correctly on the shop page? If so, please, provide us your admin and FTP access so we can check it.

    Regards

    #52131

    There I send you some pics to help you understand better the case. Thank you in advance.

    #52196

    Hello,

    Please upload your screens once more something is wrong with your previous attempt

    Best Regards

    #52344

    Ok they were bigger than allowed file size.

    Attachments:
    You must be logged in to view attached files.
    #52355

    Hello,

    When you set to show, for example, 8 products but actually you have in this category or among new products, only six you will have the gap. Make sure that you have eight new products and you have four or eight products in the category shown on this screenshot. https://xtemos.nyc3.digitaloceanspaces.com/wp-content/uploads/2018/04/112.jpg

    Best Regards

    #52583

    I have 10 products in database with the NEW label, and have set to display 8 products per page in this carousel. The 8th products is out of stock and is being hiding from woocommerce, and I have this gap. Normaly the 9th product would have taken the place of 8th “invisible” product. It seems that the carousel doesn’t take into account if the woocommerce is hiding this product due to availability and it tries to display it, and for this reason i have this gap.

    #52589

    Hello,

    In your case, there is sense to set 9 products or 12 per page. Carousel element takes default WooCommerce products and if you set it not visible. It is not visible by setting in Woocomerce but on in the element. Please check and inform.

    Best Regards

    #52633

    Thank you, although it is working by setting 9 elements per page, once the product become available again then i will have 3 lines as show in the picture. The last line will be incomplete, so there is no homogeneity. So for me this is no actual permanent, solution. I was wondering if you can make it more clever to know what products are being hidden (out of stock) and to ignore them.

    Attachments:
    You must be logged in to view attached files.
    #52682

    Artem Temos
    Keymaster

    We can’t connect your server with the FTP access you provided. Could you please check it?

    #52702

    Strange, i send you again.

    #52714

    Artem Temos
    Keymaster

    Try to add the following PHP code snippet to the child theme functions.php file to fix this

    	function woodmart_shortcode_products( $atts, $query = false ) {
    		
    	    $parsed_atts = shortcode_atts( woodmart_get_default_product_shortcode_atts(), $atts );
    
    		extract( $parsed_atts );
    
    	    $is_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX && $force_not_ajax != 'yes' );
    
    	    $parsed_atts['force_not_ajax'] = 'no'; // :)
    
    	    $encoded_atts = json_encode( $parsed_atts );
    
    		$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    
    		if( $ajax_page > 1 ) $paged = $ajax_page;
    
    		$ordering_args = WC()->query->get_catalog_ordering_args( $orderby, $order );
    
    		$meta_query   = WC()->query->get_meta_query();
    
    		$tax_query   = WC()->query->get_tax_query();
    		
    		if ( $post_type == 'new' ){
    			$meta_query[] = array(
    				'key'     => '_woodmart_new_label',
    				'value'   => 'on',
    				'operator' => 'IN',
    			);
    		}
    
    		if( $orderby == 'post__in' ) {
    			$ordering_args['orderby'] = $orderby;
    		}
    
    	    $args = array(
    	    	'post_type' 			=> 'product',
    	    	'post_status' 			=> 'publish',
    			'ignore_sticky_posts' 	=> 1,
    	    	'paged' 			  	=> $paged,
    			'orderby'             	=> $ordering_args['orderby'],
    			'order'               	=> $ordering_args['order'],
    	    	'posts_per_page' 		=> $items_per_page,
    	    	'meta_query' 			=> $meta_query,
    	    	'tax_query'             => $tax_query,
    		);
    
    		if( ! empty( $ordering_args['meta_key'] ) ) {
    			$args['meta_key'] = $ordering_args['meta_key'];
    		}
    
    		if( $post_type == 'ids' && $include != '' ) {
    			$args['post__in'] = explode(',', $include);
    		}
    
    		if( ! empty( $exclude ) ) {
    			$args['post__not_in'] = explode(',', $exclude);
    		}
    
    		if( ! empty( $taxonomies ) ) {
    			$taxonomy_names = get_object_taxonomies( 'product' );
    			$terms = get_terms( $taxonomy_names, array(
    				'orderby' => 'name',
    				'include' => $taxonomies
    			));
    
    			if( ! is_wp_error( $terms ) && ! empty( $terms ) ) {
    				if( $post_type == 'featured' ) $args['tax_query'] = array( 'relation' => 'AND' );
    
    				if( count( $terms ) > 1 ) $args['tax_query']['categories'] = array( 'relation' => 'OR' );
    
    				foreach ( $terms as $term ) {
    					$args['tax_query']['categories'][] = array(
    						'taxonomy' => $term->taxonomy,
    					    'field' => 'slug',
    					    'terms' => array( $term->slug ),
    					    'include_children' => true,
    					    'operator' => 'IN'
    					);
    				}
    			}
    		}
    
    		if( $post_type == 'featured' ) {
    			$args['tax_query'][] = array(
    				'taxonomy' => 'product_visibility',
    				'field'    => 'name',
    				'terms'    => 'featured',
    				'operator' => 'IN',
    			);
    		}
    
    		if ( 'yes' === get_option( 'woocommerce_hide_out_of_stock_items' ) ) {
    			$args['meta_query'][] = array( 'key' => '_stock_status', 'value' => 'outofstock', 'compare' => 'NOT IN' );
    		}
    
    		if( ! empty( $order ) ) {
    			$args['order'] = $order;
    		}
    
    		if( ! empty( $offset ) ) {
    			$args['offset'] = $offset;
    		}
    
    		if( $post_type == 'sale' ) {
    			$args['post__in'] = array_merge( array( 0 ), wc_get_product_ids_on_sale() );
    		}
    
    		if( $post_type == 'bestselling' ) {
    			$args['orderby'] = 'meta_value_num';
    			$args['meta_key'] = 'total_sales';
    		}
    		
    		if ( empty( $product_hover ) || $product_hover == 'inherit' ) $product_hover = woodmart_get_opt( 'products_hover' );
    		
    		woodmart_set_loop_prop( 'timer', $sale_countdown );
    		woodmart_set_loop_prop( 'product_hover', $product_hover );
    		woodmart_set_loop_prop( 'products_view', $layout );
    		woodmart_set_loop_prop( 'is_shortcode', true );
    		woodmart_set_loop_prop( 'img_size', $img_size );
    		woodmart_set_loop_prop( 'products_columns', $columns );
    		
    		
    		if ( $products_masonry ) woodmart_set_loop_prop( 'products_masonry', ( $products_masonry == 'enable' ) ? true : false );
    		if ( $products_different_sizes ) woodmart_set_loop_prop( 'products_different_sizes', ( $products_different_sizes == 'enable' ) ? true : false );
    
    		$products = new WP_Query( $args );
    
    		WC()->query->remove_ordering_args();
    
    		// Simple products carousel
    		if( $layout == 'carousel' ) return woodmart_generate_posts_slider( $parsed_atts, $products );
    
    		if ( $pagination != 'arrows' ) {
    			woodmart_set_loop_prop( 'woocommerce_loop', $items_per_page * ( $paged - 1 ) );
    		}
    
    		if ( $layout == 'list' ) {
    			$class .= ' elements-list';
    		}else{
    			$class .= ' woodmart-spacing-' . $spacing;
    			$class .= ' products-spacing-' . $spacing;
    			$class .= ' grid-columns-' . $columns;
    		}
    		
    		$class .= ' pagination-' . $pagination;
    		
    		if( woodmart_loop_prop( 'products_masonry' ) ) $class .= ' grid-masonry';
    
    		ob_start();
    
    		if( ! $is_ajax) echo '<div class="woodmart-products-element">';
    
    	    if( ! $is_ajax && $pagination == 'arrows' ) echo '<div class="woodmart-products-loader"></div>';
    
    	    if( ! $is_ajax) echo '<div class="products elements-grid row woodmart-products-holder ' . esc_attr( $class ) . '" data-paged="1" data-atts="' . esc_attr( $encoded_atts ) . '" data-source="shortcode">';
    
    		if ( $products->have_posts() ) :
    			while ( $products->have_posts() ) :
    				$products->the_post();
    				wc_get_template_part( 'content', 'product' );
    			endwhile;
    		endif;
    
        	if( ! $is_ajax ) echo '</div>';
    
    		if ( function_exists( 'woocommerce_reset_loop' ) ) woocommerce_reset_loop();
    		
    		wp_reset_postdata();
    		
    		woodmart_reset_loop();
    
    		if ( $products->max_num_pages > 1 && ! $is_ajax ) {
    			?>
    		    	<div class="products-footer">
    		    		<?php if ( $pagination == 'more-btn' || $pagination == 'infinit' ): ?>
    		    			<a href="#" class="btn woodmart-load-more woodmart-products-load-more load-on-<?php echo ( $pagination == 'more-btn' ) ? 'click' : 'scroll'; ?>"><span class="load-more-label"><?php esc_html_e( 'Load more products', 'woodmart' ); ?></span><span class="load-more-loading"><?php esc_html_e( 'Loading...', 'woodmart' ); ?></span></a>
    		    		<?php elseif ( $pagination == 'arrows' ): ?>
    		    			<div class="wrap-loading-arrow">
    			    			<div class="woodmart-products-load-prev disabled"><?php esc_html_e( 'Load previous products', 'woodmart' ); ?></div>
    			    			<div class="woodmart-products-load-next"><?php esc_html_e( 'Load next products', 'woodmart' ); ?></div>
    		    			</div>
    		    		<?php endif ?>
    		    	</div>
    		    <?php
    		}
    
        	if( ! $is_ajax ) echo '</div>';
    
    		$output = ob_get_clean();
    
    	    if( $is_ajax ) {
    	    	$output =  array(
    	    		'items' => $output,
    	    		'status' => ( $products->max_num_pages > $paged ) ? 'have-posts' : 'no-more-posts'
    	    	);
    	    }
    
    	    return $output;
    
    	}
    	add_shortcode( 'woodmart_products', 'woodmart_shortcode_products' );
    #52715

    Thank you, it works now perfect. Question, do you plan to include this function in any following update, so as i will have in mind to check in the future and remove the fuction if you include it by default?

    #52721

    Artem Temos
    Keymaster

    It is a hotfix and we should find some general solution in the future. We suggest you to keep that code in the child theme since we can’t guarantee that we will change it in the next update. It is strange that this problem appears for you only.

    #52722

    Ok, thank you.

Viewing 15 posts - 1 through 15 (of 15 total)

The topic ‘Products with NEW label and hiding out of stock products’ is closed to new replies.