Viewing 15 replies - 1 through 15 (of 15 total)
  • Plugin Contributor alexmigf

    (@alexmigf)

    Hello @mashalshaikh

    Yes you can, locations are terms of the taxonomy “location”, you should be able to query by term like these:

    $args = array(
        'post_type'			=> 'product',
        'post_status' 		=> 'publish',
        'tax_query' => array(
            array(
                'taxonomy' 	=> 'location',
                'field' 	=> 'slug',
                'terms' 	=> 'some-location'
            ),
    	),
    	'posts_per_page' 	=> -1,
    );
    
    $your_query = new WP_Query( $args );

    How do you apply this? I’d like to see products per location on product page? Also is there a way for client to select location on cart, or can it sync with a pick up location?

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @djsieff

    I’d like to see products per location on product page?
    A: You mean other products? I’m confused, can you explain better what you want to achieve?

    Also is there a way for client to select location on cart, or can it sync with a pick up location?
    A: At this time unfortunately no.

    • This reply was modified 6 years, 2 months ago by alexmigf.

    on the product page displayed to the customer, I need them to see instead of just instock with the stock amount total, they will see each location stock total, so they know if they wanted to drive to pickup the item, they know that that location has stock.

    What is this code for? where do you paste it into?

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @djsieff

    Ok, it’s the same situation of here. I will release an update today with a new shortcode for that.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hi @djsieff

    I have released a new update, please use this shortcode:

    [slw_product_locations show_qty=”yes” show_stock_status=”no” show_empty_stock=”yes”]

    Thanks for sorting that our quick, unfortunately that doesn’t work it only shows locations but not the quantities and does not remove the woocommerce total. Is there a way you can make more of a settings tick box on/off option instead of a shortcode? pasting this on every product page would take a while.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @djsieff

    Please, use this inside the product loop in a template:

    <?php
    	$stock_locations = get_the_terms( get_the_ID(), 'location' );
    	echo '<ul>';
    	foreach( $stock_locations as $location ) {
    		echo '<li>'.$location->name.': '.$location->count.'</li>';
    	}
    	echo '</ul>';
    ?>

    I don’t have plans to do frontend stuff with this plugin.

    Hope that helps.

    Hi Alex,

    In your code snippet to @djsieff you gave the .$location->count. Is there another variable we can use to show the stock_qty as I’ve used the snippet in the single-product.php page and the results shows the location.name and location.count as e.g.
    Store A: 1
    Store B: 1
    however the stock qty for Store A is 14 and for store B is 8

    Many thanks in advance and nice job on this plugin!

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @marekinfomasters

    Your product is simple or variable? Let me know.

    Hello @alexmigf, the example was for a simple, however it’s showing the same on a variable as well.

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @marekinfomasters

    Could you send me an email please? I will try to help you.

    Plugin Contributor alexmigf

    (@alexmigf)

    Code updated for both, simple and variable products:

    <?php
    	$product = wc_get_product(get_the_ID());
    	$stock_locations = get_the_terms( get_the_ID(), 'location' );
    	if( !empty($stock_locations) ) {
    		if( $product->get_type() == 'variable' ) {
    			if( !empty($variations = $product->get_available_variations()) ) {
    				foreach( $variations as $variation ) {
    					$variation_product = wc_get_product($variation['variation_id']);
    					foreach( $attributes = $variation_product->get_variation_attributes() as $attribute ) {
    						echo '<label class="slw-variation-'.$attribute.'-locations" style="font-weight:bold;">'.ucfirst($attribute).'</label>';
    					}
    					echo '<ul>';
    					foreach( $stock_locations as $location ) {
    						$location_stock = $variation_product->get_meta('_stock_at_'.$location->term_id);
    						echo '<li>'.ucfirst($location->name).': '.$location_stock.'</li>';
    					}
    					echo '</ul>';
    				}
    			}
    		} elseif( $product->get_type() == 'simple' ) {
    			echo '<ul>';
    			foreach( $stock_locations as $location ) {
    				$location_stock = $product->get_meta('_stock_at_'.$location->term_id);
    				echo '<li>'.ucfirst($location->name).': '.$location_stock.'</li>';
    			}
    			echo '</ul>';
    		}	
    	}
    ?>

    Can you tell an inexperienced user exactly where to insert this code?

    Plugin Contributor alexmigf

    (@alexmigf)

    Hello @scdjeday

    You have to add it to your product template inside the loop. What theme are you using?

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

The topic ‘show location wise products’ is closed to new replies.