By ticking the "hide unavailable products option" in Prices by Country > Catalogue (see https://prnt.sc/gs6xcp), the Prices by Country plugin checks if a product is available for a specific country, and sets a visibility status against it. WooCommerce uses the status while displaying the product catalogue, hiding the unavailable products.


There could be a few reasons why some products could still be visible after selecting a country for which they should be hidden.

 

1. Caching

If you use a caching system that is not configured to support dynamic caching, your site might be displaying stale cached content. When this happens, the Prices by Country plugin and its logic are ignored, as the cached content is served "as is" to all visitors. To fix the issue, the caching system should be set up to take into account the active country. If this is not possible, then a workaround such as the Aelia Cache Handler plugin should be used instead. You can read more about dynamic caching and the Cache Handler plugin here: How to add dynamic caching to your site


2. The theme/widget showing the products ignores their visibility status

Each product has a "visible" status, which WooCommerce queries before displaying the products in the catalogue. While going through the products, WooCommerce performs a $product->is_visible() check. When a product is not visible, then it's not displayed on the catalogue. The Prices by Country plugin taps into that status, changing it on the fly depending on customer's country (i.e. setting it to "visible" for one country, and "not visible" for another). For the products to be hidden, any widget or theme that shows them should take that visibility status into account. If they don't, then they will always show the products, ignoring the visibility settings.


In technical terms, any code that goes through a list of products should perform check like the following:

// Loop through a list of products and show the visible ones
foreach($products as $product_to_show) {
  // Skip invisible products
  if(!$product_to_show->is_visible()) {
    continue;
  }
  // Show the product
}

One easy way to check if this is the case is to switch temporarily to another theme (e.g. Storefront) and load the catalogue page. If the products are hidden on that page with Storefront, then it means that the theme, or some plugin you are using to render the catalogue is showing them by ignoring their visibility status. In such case, the rendering code should be corrected by adding the aforementioned check against product visibility.

 

3. Something is changing the product visibility status after the Prices by Country plugin sets it as "hidden"

The visibility status can be changed by any plugin. If there is a plugin, or some custom code, that changes the status after the Prices by Country plugin, then products can be forced to be visible by such plugin/code. You can check this with a simple filter, to add to your theme's functions.php (see https://www.skyverge.com/blog/add-custom-code-to-wordpress/):

/**
 * This filter forces all products to be not visible, regardless of any other settings.
 */
add_filter('woocommerce_product_is_visible', function($visible) {
  return false;
}, 11, 1);

With this filter, you should not see any product at all on the catalogue. If you do, then it means that something else is changing the visibility status back to "visible". In such case, it should be possible to find out what is doing that by going by exclusion. Here's the most common process to exclude elements one by one:

  1. Create a staging copy of the site.
  2. On the staging copy, disable all the plugins (keep WooCommerce, the Prices by Country plugin and the Aelia Foundation Classes) and switch to a basic theme (e.g. Storefront), to exclude any custom code that might be causing the glitch.
  3. Reload the catalogue page.
  4. If the products are now invisible, as expected, enable one of the plugins you disabled at #2 and repeat the test.
  5. Repeat #4 until the issue occurs again. This will tell you which element(s) contribute to it.


Related articles


You can purchase the Prices by Country plugin from our online shop.