List WooCommerce Products by Tags – wordpress plugin

Today, We want to share with you List WooCommerce Products by Tags – wordpress plugin.In this post we will show you how to get all product tag in woocommerce, hear for WooCommerce Product Tags on a Single Page we will give you demo and example for implement.In this post, we will learn about List WooCommerce Products Based on Category, Tag, ID & More with an example.

List WooCommerce Products by Tags – wordpress plugin

There are the Following The simple About List WooCommerce Products by Tags – wordpress plugin Full Information With Example and source code.

As I will cover this Post with live Working example to develop how to show woocommerce products on page, so the How to display WooCommerce products on the homepage for this example is following below.

Read Also:  like and dislike button code in php

Here is a quick way to list WooCommerce products by tags using a simple shortcode. To use it, simply place the following shortcode within your pages:

[Woocommerce_products_by_tags tags=”mobiles,laptops”].

We created a simple plugin to do the job. step by step copy and paste the code below in new file called “woocommerce-products-by-tags.php” within a “wp-content/plugins/woocommerce-products-by-tags” folder.

<?php
/**
 * Plugin Name: WooCommerce - List Products by Tags
 * Plugin URI: https://www.pakainfo.com/wordpress-woocommerce-get-product-tags/
 * Description: List WooCommerce products by tags using a shortcode, ex: [Woocommerce_products_by_tags tags="mobiles,laptops"]
 * Version: 1.0
 * Author: Pakainfo
 * Author URI: https://www.pakainfo.com
 * Requires at least: 1.5
 * Tested up to: 2.0
 *
 * Text Domain: -
 * Domain Path: -
 *
 */
/*
 * List WooCommerce Products by tags
 *
 * ex: [Woocommerce_products_by_tags tags="mobiles,laptops"]
 */
function Woocommerce_products_by_tags_shortcode( $atts, $content = null ) {
  
  // Get WooCommerce attribuets
  extract(shortcode_atts(array(
    "tags" => ''
  ), $atts));
  
  ob_start();
  // Define Query Arguments
  $args = array( 
        'post_type'    => 'product', 
        'posts_per_page' => 10, 
        'product_tag'    => $tags 
        );
  
  // Create the new query
  $loop = new WP_Query( $args );
  
  // Get products number
  $product_count = $loop->post_count;
  
  // If results
  if( $product_count > 0 ) :
  
    echo '<ul class="products">';
    
      // WooCommerce simple products Start the loop
      while ( $loop->have_posts() ) : $loop->the_post(); global $product;
      
        global $post;
        
        echo "<p>" . $thePostID = $post->post_title. " </p>";
        
        if (has_post_thumbnail( $loop->post->ID )) 
          echo  get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); 
        else 
          echo '<img src="'.$woocommerce->plugin_url().'/assets/images/placeholder.png" alt="" width="'.$woocommerce->get_image_size('shop_catalog_image_width').'px" height="'.$woocommerce->get_image_size('shop_catalog_image_height').'px" />';
    
      endwhile;
    
    echo '</ul><!--/.products-->';
  
  else :
  
    _e('sorry, No Any product matching your tags related products.');
  
  endif; // WooCommerce endif $product_count > 0
  
  return ob_get_clean();
}
add_shortcode("Woocommerce_products_by_tags", "Woocommerce_products_by_tags_shortcode");

Web Programming Tutorials Example with Demo

Read :

Read Also:  Angularjs Show Hide Password in Password TextBox with CheckBox

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about WooCommerce Products by Tags – wordpress plugin.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Angular Add Directives Dynamically Example
  2. Read Also:  Laravel 6 group by month/year using Eloquent
  3. Read Also:  Wordpress woocommerce get product tags
  4. Read Also:  JQuery AJAX form Submit and serialize send Server Side
  5. Read Also:  how to Convert a string to int in C++ ?
  6. Read Also:  Woocommerce Get product tags in array
  7. Read Also:  how to create horizontal tabs in html?
  8. Read Also:  PHP Get domain name from full URL with parameters
  9. Read Also:  Laravel File Upload Progress Bar Example Tutorial
  10. Read Also:  PHP mysqli insert update delete for Dynemic query
CLOSEX