Posts

news icon

WooCommerce and cache – Part 2: new Cache Handler plugin

Read Part 1: WooCommerce Currency Switcher and cache – Making them work together

Some months ago, we wrote about one of the most common issues faced by merchants who run highly dynamic websites, which include multi-currency, multi-pricing, geolocation features: stale content served by rigid caching systems.

In brief, there are quite a few caching systems designed with the assumption that the content of a site is the same for anyone. No matter who is opening a page, they serve the same information. This is correct for relatively static sites, such as blogs, which show the same articles to every member of the audience, or simple e-shops, where the prices are set, and are the same for every customer.

In a few words, many caching systems assume that, given a page on a site, the content of such page will always be the same, without exception. As we explained, this is incorrect when a site is highly dynamic. A shop that handles multiple currencies may be showing different prices to different visitors, or it might need to show a different tax rate (this is actually a requirement in many countries), on the exact same page.

With a static caching system, the result is that users may end up seeing the wrong content. This makes for a worse user experience, and can have an impact on conversion.

After an in-depth analysis, and several experiments, we came to a conclusion: issues caused by the caching system must be solved by the caching system. Based on this approach, we prepared an algorithm for dynamic caching that handles the needs of a multi-currency, multi-pricing, multi-language shop as it should, without compromising on the performance. This, in our opinion, is the correct way to address the issue.

The status of Dynamic Caching today

We keep contacting as many hosting providers as possible, explaining them how they should update their caching systems to bring them up to speed. Our objective is to make it clear that handling highly dynamic caching is a must, not just a “frill”.

Quite a few providers agreed with our approach, and allow their customers to customise the caching logic as required. Others, like the WP Engine team, showed interest in our solution, and are currently reviewing it, for future implementation. There are some who are still “lagging behind”, and there are a few, such as CloudFlare, who only offer dynamic caching on their most expensive plans.

Due to these limitations, imposed by an obsolete architecture, merchants have make a difficult decision:

  • Change hosting/service provider and move to one that handles caching as it should. This would make sense, but it’s not always possible. Besides, merchants might have invested a significant sum in current service.
  • Disable the caching system they are using, and for which they might have been paying a service fee.
  • Abandon the idea of a multi-currency, multi-language site, potentially risking to drive away audience.

While we still maintain that caching issues must be addressed on the caching layer, we wanted to find a solution that would help merchants, at least temporarily, while the service providers update their system.

Welcome our new plugin: WooCommerce Cache Handler

Thanks to our customers’ support, we are happy to announce the release of the WooCommerce Cache Handler plugin (currently in Beta stage). This new plugin can be used as a workaround with rigid caching systems, such as CloudFlare, SiteGround “Dynamic” Cache (which is actually static), as well as plugins that don’t support dynamic caching, such as W3 Total Cache.

Please note that our recommendation is still to consider switching to a more flexible solution, but this plugin will cover you until you are ready for that change.

How it works

The WooCommerce Cache Handler is simple to use. All you have to do after installing the plugin is go to WooCommerce Settings > Cache Handler and choose the handler you prefer.

WooCommerce Cache Handler - Configuration page

Configuring WooCommerce Cache Handler is extremely easy. Simply choose your favourite handler, clear the cache, and you are ready to go!

After that simple selection, the Cache Handler will support our Currency Switcher, Prices by Country, Tax Display by Country, and all our other WooCommerce plugins.

Currently, there are three options available.

1. Disabled

As the name implies, this disable all the features of the plugin. It can be useful for testing.

2. Redirect

This option is an almost exact equivalent of the “caching support” feature implemented by WooCommerce, which is enabled when the Default Customer Address is set to Geolocate (with page caching support).

The major difference from the standard feature is that our handler takes into account details such as the currency, customer’s country, customer’s state, customer’s tax exemption, and so on, ensuring that the correct content is served to customers based on these parameters. Like the original workaround from which it was derived, this handler appends a random string to URLs.

Benefits and drawbacks

+ The Redirect handler is based on the original workaround implemented by WooCommerce.
+ This solution works on a page level, thus it can produce the correct content with any configuration, or 3rd party plugins.
– The URLs look “ugly”, due to the string appended to them to work around the limitations of caching.

3. Ajax Loader

The Ajax Loader is an alternative to the Redirect, and it’s more elegant, as it doesn’t alter page URLs with ugly, random text. This handler loads all pricing elements via Ajax, when the page load is completed. The result is the following:

  1. A visitor connects to your site from the US. He would like to see USD.
  2. The rigid caching system has the page cached in EUR, and serves it to the customer.
  3. The Ajax Loader kicks in as soon as the page is loaded, requesting the updated prices from the server. After a brief moment, all elements that were displayed in EUR are changed to USD, as the visitor would expect.This update is very quick, and, at the moment, it processes the following standard elements :
    – Product prices
    – Currency selectors
    – Price filter widget
    – Custom prices displayed with the Currency Switcher shortcodes.

Benefits and drawbacks

+ The Ajax Loader is a more elegant solution than reloading the page after appending a random string to the URL.
+ Page load is faster, as there is no redirect.
+ URLs are not altered. There is no random text appended to them.
– The Ajax Loader can only process standard elements on the page. If 3rd party plugins add their own pricing elements, such addon prices, custom totals, etc, those won’t be updated. It will be up to the 3rd party plugins’ authors to “hook” into the Ajax Loader and refresh their elements via Ajax.

How to get the WooCommerce Cache Handler

The WooCommerce Cache Handler is available free of charge. Please feel free to download and try it, and see how it works for you. Whether you are using CloudFlare, SiteGround, WP Engine, Flywheel, or any other service with static caching, the Cache Handler got you covered!

Questions? Feedback?

The Cache Handler is still in Beta stage and that, as any free plugin, it’s not covered our free support. We would recommend to try it on a staging copy of your site, so that the live site won’t not affected by bugs that we eventually have to address.

We also would like to encourage you to share your feedback by contacting us. If you wish to contribute to the development of this plugin, you are more than welcome to do so!

Thanks for reading, and see you soon on aelia.co!

The Aelia Team

news icon

WooCommerce Tips & Tricks – Get all the categories to which a product belongs

As active contributors of several communities, such as the Advanced WooCommerce and WooCommerce Help & Share groups on Facebook, we came across a question that seem to be quite frequent.

How to get all of a product’s categories

This operation is simple, it just requires a bit more work than one would expect. It’s very easy to fetch the categories to which a product is assigned directly, but a product may also belong to parent categories (a parent category is a category to which a subcategory belongs). The screenshot below explains the concept.

Product category hierarchy

In this example, the product belongs directly to “Subcategory A1” and “Some other category”. It also belongs indirectly to “Category A”, as “Subcategory A1” is a child of that category.

In the above example, the product belongs to the following categories:

  • Directly to Subcategory A1 and Some other category, as it’s assigned directly to them.
  • Indirectly to Category A, which is the parent of Subcategory A1.

Now that the concepts are clear, let’s get coding.

Step 1 – Get the direct categories of a product

This is the easiest part. It’s just a matter to find all the “category” terms associated to a product. Our function will look like this:

function aelia_get_product_categories($product, $return_raw_categories = false) {
  $result = array();
  // Get all the categories to which a product is assigned
  $categories = wp_get_post_terms($product->id, 'product_cat');
  
  // The $categories array contains a list of objects. Most likely, we would 
  // like to have categorys slug as a keys, and their names as values. The#
  // wp_list_pluck() function is perfect for this
  $categories = wp_list_pluck($categories, 'name', 'slug');
  return $categories;
}

The result of this function, once applied to our example product, will be the following:

array(
  'subcategory-a1' => 'Subcategory A1',
  'some-other-category' => 'Some other category',
)

All good, we have the categories to which the product is assigned directly. Now we need to get all the parent categories.

Step 2 – Get the parent category (or categories) of a given category

To keep things tidy, we will create a second function to get the parent categories of a category. This requires a similar approach to the one used for the products.

function aelia_get_parent_categories($category_id) {
  $parent_categories = array();
  // This will retrieve the IDs of all the parent categories 
  // of a category, all the way to the top level
  $parent_categories_ids = get_ancestors($category_id, 'product_cat');
  
  foreach($parent_categories_ids as $category_id) {
    // Now we retrieve the details of each category, using its
    // ID, and extract its name
    $category = get_term_by('id', $category_id, 'product_cat');
    $parent_categories[$category->slug] = $category->name;
  }
  return $parent_categories;
}

The above will return the following result for Subcategory A1:

array(
  'category-a' => 'Category A'
)

As before, we have a list with category slugs as keys, and category names as values. Time to finish the job.

Step 3 – Putting the pieces together

Now that we can get both the direct categories of a product and their parent categories, we can alter the first function to call the second and give us a result that includes all the categories. The modified function will look as follows:

function aelia_get_product_categories($product, $return_raw_categories = false) {
  $result = array();
  $categories = wp_get_post_terms($product->id, 'product_cat');

  if(is_array($categories) && !$return_raw_categories) {
    $parent_categories = array();
    // Retrieve the parent categories of each category to which
    // the product is assigned directly
    foreach($categories as $category) {
      // Using array_merge(), we keep a list of parent categories
      // that doesn't include duplicates
      $parent_categories = array_merge($parent_categories, aelia_get_parent_categories($category->term_id));
    }
    // When we have the full list of parent categories, we can merge it with
    // the list of the product's direct categories, producing a single list
    $categories = array_merge($parent_categories, wp_list_pluck($categories, 'name', 'slug'));
  }
  return $categories;
}

As you will probably have guessed, the new function will return the following result:

array(
  'subcategory-a1' => 'Subcategory A1',
  'some-other-category' => 'Some other category',
  'category-a' => 'Category A',
)

That is, a list of all the direct and indirect categories to which a product belongs. Mission accomplished!

For your convenience, you can find the complete code here: WooCommerce – WooCommerce – Get product categories, including parent categories (Pastebin).

Need help?

Should you need help implementing the solution, or if you would need to have the category search functions implemented as part of a more complex custom project, please feel free to contact us. We will review your specifications and give you a quote for your customisation.

The Aelia Team

news icon

SIP Frontend Bundler now supports Aelia Currency Switcher for WooCommerce

We are delighted to inform you that a new plugin joined the multi-currency family. The SIP Frontend Bundler, developed by ShopitPress, now includes full support for our ever popular Currency Switcher for WooCommerce. Together, they will grant you unprecedented flexibility in offering attractive bundles to your customers, helping you increasing your revenue.

What can the SIP Front End Bundler do for you?

In short, it allows your customers to configure and buy product bundles, straight from your front page. The price is updated in real time, so that the buyer can immediately see how much he is going to spend, and adjust the bundle accordingly. Easy to explain, easy to use!

Some of the exclusive features provided by the SIP Front End Bundler

  • Let customer crate their own bundle
    No need to spend time creating pre-configured bundles, one by one, hoping to get it “just right”. Just select the products that can be bundled together, and let your customers create their own set.
  • Real-time price display
    Customers like to know in advance how much they are going to spend, possibly without having to manually compare multiple product combinations. The SIP Frontend Bundler will show them how much they are saving in real-time, as the customer build its own bundle.
  • Build your bundle from anywhere
    The SIP Front End Bundler for WooCommerce can show the bundle builder in any page on your site. Your customers will love to create their own bundles right from the front page, instead of having to go through a long catalogue.
  • Fully supports the Aelia Currency Switcher
    Thanks to the collaboration between Aelia and ShopitPress, the SIP Front End Bundler includes full support for our Currency Switcher for WooCommerce. Sell your bundles in multiple currencies and increase conversion!

Multi-currency Bundles in WooCommerce, made easy!

This is another great result of a collaboration between teams who share the same vision, and who recognise the importance of being able to offer your products to a worldwide audience, catering to a large range of needs. Just like our Currency Switcher for WooCommerce, which was born to grant customers the flexibility to pay in their preferred currency, the SIP Front End Builder grants them the freedom to create their own special offers, quickly and easily.

We would like to thank the ShopitPress team for the effort they put in developing such a powerful, yet easy to use solution for the management and creation of bundles. Well done, and keep up the good work!

Are you a plugin developer?

If you are a plugin developer, and would like to learn how to add multi-currency capabilities to your products, please feel free to get in touch. We will be happy to give you the information you need for a quick start, as well as examples that will simplify the integration with our Currency Switcher for WooCommerce. You will join the ever-growing list of teams who support such an important feature, amongst which you can find SkyVerge, Prospress, YIThemes, ThemeComplete and, of course, ShopitPress.

Thanks for reading, and see you soon for more great news!

The Aelia Team

news icon

WP Rocket now supports Aelia Currency Switcher for WooCommerce

We have just been informed that WP Rocket 2.7 was released on the 11th March. Amongst the many improvements, in this version the WP Media team added native support for our Currency Switcher. That’s right: you can now use WP Rocket with our leading multi-currency solution, and our other WooCommerce plugins, out of the box, and there is no configuration required. They will simply work together.

WP Rocket + Aelia Currency Switcher = Lightning fast multi-currency shops

Praised by many as one of the best caching plugins on the market, in terms of speed and ease of use, WP Rocket is now an excellent choice for all the merchants who need to run busy, multi-currency WooCommerce shops and need top performance.

Thanks to its zero-configuration, smart integration, WP Rocket will detect our Currency Switcher for WooCommerce, automatically adjust its caching strategy to support multiple currencies, and serve the correct content to all visitors.

As added bonuses, WP Rocket now supports the additional features added by the Aelia plugins:

  • Geolocation
    Our products use a geolocation mechanism that we introduced long before the WC team introduced it in WooCommerce. Our solution is cache-friendly and provides better performance than the official one.
  • Prices by Country
    Customers will see the correct prices, prepared by our plugin depending on customer’s country.
  • Tax Display by Country
    Customers will  see prices including or excluding taxes, depending on customer’s country.

All the above, and more, is now available together with all the benefits of the powerful caching provided by WP Rocket.

Improving WooCommerce, together

This is the beginning of a new partnership between Aelia and WP Media. By combining the flexibility offered by our products and the performance provided by WP Rocket, we will bring the global market as close to you as possible, and expand your audience to its maximum potential.

As usual, be ready for more great news, coming soon!

The Aelia Team

news icon

YITH Gift Cards now supports Aelia Currency Switcher for WooCommerce

Great news for all our customers! The YITH Team informed us that their popular YITH WooCommerce Gift Cards plugin now includes full support for our leading multi-currency solution for WooCommerce, the Aelia Currency Switcher.

Thanks to this great new feature, you will now be able to give your clients the option to buy gift cards in their currency of choice. This will make your shop more attractive than ever, and help increasing conversion rate.

We would like to thank the YITH team for the great work done so far. We share the same roots (our founder is Italian too) and we are particularly proud of their success and continuous improvements.

We will keep working with them and other developers to extend multi-currency support to as many plugins as possible. Together, we will make WooCommerce the most flexible ecommerce solution, covering the needs of a global market.

Stay tuned for more great news, coming soon!

The Aelia Team

news icon

Wholesale Pricing plugin now supports our Currency Switcher for WooCommerce

The Wholesale Plugin joins the multi-currency family

We have been informed by our colleagues at Rymera Web Co that their Wholesale Pricing plugin now includes native support for our popular Currency Switcher for WooCommerce. This means that you will be able to take advantage of the multi-currency features provided by our plugin when setting wholesale prices, making your pricing strategy more flexible than ever.

Your wholesale clients will be pleased to see prices in their own currency, and you will be able to give them tailored offers. Now, that’s fantastic news!

Would you like to help? You can!

If you are a customer, and would like to enjoy the benefits of a multi-currency shop, but you use one or more incompatible plugins, simply contact the plugins’ authors. Let them know how important it is to support multiple currencies, in a global market, and ask them to add support for it in their products. Tell them that they can contact us at any time, and we will help them getting started in no time.

If you are a plugin developer, and would like to make your plugin multi-currency aware, simply get in touch. We will be happy to provide you with instructions, suggestions and examples to get you started. It’s easier than it seems!

Acknowledgements

We would like to thank the Rymera Web Co team for the effort they put in developing the integration with our Currency Switcher for WooCommerce. Having their product join the ever growing family of multi-currency plugins surely involved a lot of work, and it will contribute to strengthen our cause. We are steadily growing, and soon having multiple currencies will become the standard.

Thanks to you all, customers and developers, for your invaluable support and efforts!

The Aelia Team