Posts

news icon

WooCommerce 2.5 – Product Compatibility Status

WooThemes released WooCommerce 2.5 on the 18th January 2016. We started our testing process with WooCommerce 2.5 Beta1 and repeated it with RC2, to ensure the best possible compatibility with our plugins.

As of today, we haven’t encountered specific issues. We will keep testing new versions of WooCommerce in the next weeks, to check if any change could cause compatibility issues.

Important

It’s important to install WooCommerce 2.5 on a test site first. Check that all installed plugins are working correctly, run some end to end test and verify that all orders are processed correctly. If everything works fine, you can update your live site.

Compatibility status

Currency Switcher

Our WooCommerce Currency Switcher is compatible with WooCommerce 2.5. We recommend to update it to its latest version, 3.9.1.160118, to take advantage of a new filter introduced in WooCommerce. The filter will hook into shipping calculations, to ensure that formulas involving cart totals are processed correctly.

Currency Switcher Add-ons

Tax Display by Country

Compatible. The changes added to WooCommerce 2.5.x should not affect this product.

Prices by Country

Compatible.

Payment Gateways

EU VAT Assistant

Compatible since version 1.5.0.151109.

Blacklister

Compatible. This plugin should not be affected by the changes in WooCommerce 2.5.

It’s our policy to continuously test our products to make sure that any issue which might still exist is found and fixed quickly. Should you find any, please feel free to report it using our support portal: Aelia Support Portal. Thanks for your time and collaboration.

The Aelia Team

news icon

WooCommerce Tips & Tricks – Only allow specific product combinations in cart

This post was written in December 2015. Based on our tests, the code works with with WooCommerce 2.5 and 2.6. Please keep in mind that the code example are provided “as is”, without explicit or implicit warranties. You might have to adjust the code to make it work with your specific configuration.

Update – 01 March 2018

You can find a link to the code for WooCommerce 3.x at the bottom of the article. 

A member of the Advanced WooCommerce group on Facebook presented an interesting challenge. She needed to allow customers to purchase any products freely, except in one case. She had a specific product (let’s calls it Product X) that had to be purchased “alone”, without any other product being present in the cart. In short:

  • If Product X is in the cart, that must be the only product in the cart.
  • If Product X is not in the cart, any other product can be added to it and purchased at the same time.

Our friend Rodolfo, from BusinessBloomer, posted a solution that he adapted from his solution to allow only one product to the cart. It works, but in our opinion, that approach presented a few limitations:

  1. It works by emptying the cart when Product X is added after the other products. If a customer adds Product X to the cart, then he can add other products, and they will stay there.
  2. It doesn’t allow to have combinations of products (e.g. Product X and Product Y allowed together).
  3. It doesn’t make clear to the customer that other products cannot be purchased together with Product X (all products retain their “Add to cart” button, even if they should not).
  4. It empties the cart explicitly. We try to avoid this type of calls whenever possible, and rely on WooCommerce’s internal logic to decide what items should be removed, and when.

Our approach

Taking advantage of the experience gained with the development of our Prices by Country plugin, we prepared a different solution, which, in our opinion, is more flexible and user friendly. It brings the following advantages:

  • It covers the requirement described above, where a specific product (e.g. Product X) must be the only one in the cart.
  • It also allows to have more than one product allowed in the cart (e.g. Product X and Product Y), while excluding all others.
  • It clearly informs the customers that some products can’t be purchased anymore.

You can find it below, described step by step. The code can be added to the theme’s functions.php, or packaged in a plugin, if needed. It has been tested with WooCommerce up to version 2.5.

Step 1 – Keep track of what’s in the cart

The first thing to do is to determine what is in the cart. The content of the cart will dictate what else can be added to it. We do this operation only once per page load, for better performance.

/**
 * Retrieves the cart contents. We can't just call WC_Cart::get_cart(), because
 * such method runs multiple actions and filters, which we don't want to trigger
 * at this stage.
 *
 * @author Aelia <support@aelia.co>
 */
function aelia_get_cart_contents() {
  $cart_contents = array();
  /**
   * Load the cart object. This defaults to the persistant cart if null.
   */
  $cart = WC()->session->get( 'cart', null );

  if ( is_null( $cart ) && ( $saved_cart = get_user_meta( get_current_user_id(), '_woocommerce_persistent_cart', true ) ) ) {
    $cart = $saved_cart['cart'];
  } elseif ( is_null( $cart ) ) {
    $cart = array();
  }

  if ( is_array( $cart ) ) {
    foreach ( $cart as $key => $values ) {
      $_product = wc_get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );

      if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > 0 ) {
        if ( $_product->is_purchasable() ) {
          // Put session data into array. Run through filter so other plugins can load their own session data
          $session_data = array_merge( $values, array( 'data' => $_product ) );
          $cart_contents[ $key ] = apply_filters( 'woocommerce_get_cart_item_from_session', $session_data, $values, $key );
        }
      }
    }
  }
  return $cart_contents;
}

// Step 1 - Keep track of cart contents
add_action('wp_loaded', function() {
  // If there is no session, then we don't have a cart and we should not take
  // any action
  if(!is_object(WC()->session)) {
    return;
  }

  // This variable must be global, we will need it later. If this code were
  // packaged as a plugin, a property could be used instead
  global $allowed_cart_items;
  // We decided that products with ID 737 and 832 can go together. If any of them
  // is in the cart, all other products cannot be added to it
  global $restricted_cart_items;
  $restricted_cart_items = array(
    737,
    832,
  );

  // "Snoop" into the cart contents, without actually loading the whole cart
  foreach(aelia_get_cart_contents() as $item) {
    if(in_array($item['data']->id, $restricted_cart_items)) {
      $allowed_cart_items[] = $item['data']->id;

      // If you need to allow MULTIPLE restricted items in the cart, comment
      // the line below
      break;
    }
  }
});

Step 2 – Prevent disallowed product combinations

Now that we know what’s in the cart, we can prevent some products from being added to it if any of the “restricted” products are present. Emptying the cart would not work, as we would risk to throw away one of the allowed products. Instead, we simply make the disallowed products unavailable. This will have several effects:

  • If any of the disallowed products is already in the cart, WooCommerce will remove it.
  • The Add to Cart button will be replaced by a Read More button on the disallowed products. Customers won’t be able to add the products back, and will instead get a note explaining that they cannot be purchased.
// Step 2 - Make disallowed products "not purchasable"
add_filter('woocommerce_is_purchasable', function($is_purchasable, $product) {
  global $restricted_cart_items;
  global $allowed_cart_items;

  // If any of the restricted products is in the cart, any other must be made
  // "not purchasable"
  if(!empty($allowed_cart_items)) {
    // To allow MULTIPLE products from the restricted ones, use the line below
    //$is_purchasable = in_array($product->id, $allowed_cart_items) || in_array($product->id, $restricted_cart_items);

    // To allow a SINGLE  products from the restricted ones, use the line below
    $is_purchasable = in_array($product->id, $allowed_cart_items);
  }
  return $is_purchasable;
}, 10, 2);

At this stage, we have the code that fulfils the original requirements. However, we need one extra step to make it more elegant.

Step 3 – Explain customers why some products cannot be purchased anymore

As we have seen, the code in step 2 prevents some products from being added to the cart if Product X and/or Product Y are already present, but it doesn’t explain customers why. We just need to show them a message with some information about the restrictions, to make things clearer.

// Step 3 - Explain customers why they can't add some products to the cart
add_filter('woocommerce_get_price_html', function($price_html, $product) {
  if(!$product->is_purchasable() && is_product()) {
    $price_html .= '<p>' . __('This product cannot be purchased together with "Product X" or "Product Y". If you wish to buy this product, please remove the other products from the cart.', 'woocommerce') . '</p>';
  }
  return $price_html;
}, 10, 2);

Step 4 – Combining the code

For the snippets above to work together, we must combine them in the correct order. More specifically, the code from step 2 should go inside the code from step 1. Here’s the complete code, ready to be pasted in the functions.php file: http://pastebin.com/BRU1BP2E.

Update – 01 March 2018

We prepared an example of how the code can be adapted for WooCommerce 3.x. You can find the code here: https://pastebin.com/tRbJKt37.

Step 5, 6, 7, etc – Improvements

The above solution is fully functional, but it would be possible to make it more elegant and flexible. Further improvements to the code could include the following:

  • Packaging the code as a plugin. This will help avoiding global variables and could make the code tidier and easier to read.
  • Adding support for groups of restricted products (e.g. Product X and Y or Product A and B, etc).
  • Adding a dynamically generated message, showing exactly which restricted products are in the cart, instead of relying on static text.
  • Adding formatting to the message displayed to the customers.

Should you need assistance adapting the solution to your needs, or implementing any of the above optimisations, please feel free to contact us. We will review your specifications and provide you with a quote for your customisation.

The Aelia Team

news icon

SkyVerge acquires Aelia’s Braintree Extended plugin

We are happy to announce that the SkyVerge Team acquired our Braintree Extended plugin. Our product’s multi-account features and Kount integration are now part of the official Braintree plugin, and available out of the box.

Starting from version 3.0 of the Braintree payment plugin, you will be able to specify a merchant account for each of the currencies provided by our Currency Switcher for WooCommerce, without having to install a separate extension. The logic we originally implemented in our Braintree Extended plugin has been preserved and improved, allowing you to accept payments in multiple currencies straight away.

What does this mean for you

If you will update your Braintree gateway to version 3.0, you will no longer need the Aelia Braintree Extended plugin, as the features it provides are now included in the official gateway. You will have the same feature set, with a single plugin installed.

How to update the Braintree gateway

To prevent conflicts, it’s important that you follow the steps below before updating the Braintree gateway:

  1. Take note of the merchant account ID associated with each currency. You can find this information by going to WooCommerce > Checkout > Braintree.
  2. Disable and remove the Braintree Extended gateway. This is very important, as the plugin won’t work properly with the Braintree gateway 3.0.
  3. Update the official Braintree gateway to version 3.0.
  4. Go to WooCommerce > Checkout > Braintree and complete the configuration by assigning the merchant account IDs you saved at step #1 to their respective currency (see screenshot below).
    Braintree gateway - Adding multiple merchant IDs

    The new interface in the Braintree gateway 3.0 allows to enter multiple merchant IDs, assigning them to the appropriate currency.

    This reconfiguration is required because the new Braintree plugin uses a slightly different setup, and you will have to do it only once.

After completing the steps above, your payment will be sent again to the appropriate Braintree merchant account ID, depending on the currency.

More great news to come

In quality of SkyVerge collaborators, we are excited at the idea that one of the leading WooCommerce developers acquired one of our solutions and included its features in their official products. To us, this is an important recognition of the effort we put in developing our plugins, and a validation of our ideas.

This acquisition is an important step towards a full integration between our solutions and some of the most important WooCommerce products on the market. We will keep working with top class developers, such as SkyVerge and Prospress (authors of the popular Subscriptions plugin), to offer you the most powerful, reliable set of internationalisation features on the market.

Expect more great news soon from Aelia!

The Aelia Team

news icon

WooCommerce Currency Switcher and cache – Making them work together

This article continues in WooCommerce and cache – Part 2: new Cache Handler plugin

One of the most common questions we receive from our customers is how to make a highly dynamic, multi-currency, multi-pricing, geolocation-enabled sites work properly with caching enabled. This is not always an easy task, because caching systems are designed with the assumption that the content served by a site doesn’t change depending on the visitor. Such assumption holds true in many cases, as a large number of sites does indeed serve the same content to whoever views a page. In such case, the standard behaviour of caching systems, which is storing one copy of each page in the cache, is acceptable.

As soon as multi-currency features are added, the same behaviour proves itself too limited, because the assumption behind it becomes incorrect. A multi-currency shop serves different content to different visitors, depending on the currency and other criteria (applicable taxes, regional pricing, etc). Quite simply, having one cached copy of each page just doesn’t cut it anymore.

Until recently, the only way to prevent caching from interfering with the multi-currency features was to disable it on catalogue pages. Doing so ensures that the shop can produce content dynamically, showing the correct information to each visitor. In some cases, when the caching system in use is too rigid, this is still the only solution.

How WooCommerce handles the issue

WooCommerce itself has to deal with caching since its team introduced geolocation features in it. The WC team added a workaround to “trick” caching systems into letting WooCommerce serve the correct data. Such workaround works by reloading the shop pages in a way that cache is ignored. This ensures that the page shows the correct content but, in our opinion, it’s not an ideal approach. We certainly appreciate the effort put into it, and the fact that there isn’t much more that a plugin can do to correct the behaviour of the caching system. However, we decided to find an alternative, more robust solution.

Our solution

Our opinion is that caching systems should adapt to your site, not the other way round. Issues caused by caching should be solved by fixing the caching. With this in mind, instead of implementing a workaround, we tackled the issue at its root, and wrote an algorithm for dynamic caching that takes into account the needs of a multi-currency website.

The algorithm is straightforward, and solves the issue by addressing its cause: instead of one copy of each page, it allows caching systems and plugins to store multiple copies of each page (such as one for each currency). With that in place, visitors from all over the world will see the content that applies to them, with the correct currency and taxes applied. If visitors choose another currency, or country, then our plugins track their choice, and the dynamic caching logic uses it to serve them the correct content.

Our solution grants top performance, with maximum flexibility.

Supported Systems

Dynamic caching is a great solution for highly dynamic, multi-currency sites. However, it can only work if the caching system in use supports it. As of October 2015, the following plugins and systems support, or are planning to support, dynamic caching.

WordPress Plugins

Caching Systems

For caching plugins and systems that do not support dynamic caching, disabling cache on catalogue pages is still necessary to allow the multi-currency features to work correctly.

How to add dynamic caching to your site

Adding it to your site can be as simple as copying one file, or changing one configuration file. In order to allow you to get started quickly, we wrote an implementation of dynamic caching for the following systems:

  • ZenCache/Comet Cache
  • Nginx

You can find detailed instructions to install and configure each of our solutions, as well as indications for other systems, in our knowledge base: How to add dynamic caching to your site.

We also discussed the implementation extensively with the WP Rocket Team, and provided them with code examples for integration. They confirmed that they are going to add support for dynamic caching and multi-currency sites directly in their plugin.

With dynamic caching and our Currency Switcher, your WooCommerce site will be faster and more flexible than ever!

What about systems that don’t support dynamic caching?

Plugins and caching systems that don’t support dynamic caching still have to be disabled on the catalogue, at least until they are updated. We believe that caching systems should be flexible, and support for dynamic caching is not particularly difficult to implement.

If you are using a plugin, or a caching system that doesn’t support dynamic caching, we recommend thar you get in touch with its authors and express your interest in such feature. You can also suggest them to contact us directly, if they have any questions. We will be happy to provide them with all the information they need to improve their solution.

Questions? Feedback?

We hope that you enjoyed this great news. A faster e-commerce means more customers, and that is always good! If you have any questions about our solutions, or if you would like to send us your feedback, please feel free to contact us. We will get back to you in no time.

Thank for your time and continued support.

The Aelia Team

news icon

More great plugins now support our WooCommerce Currency Switcher

Support for our multi-currency solution is growing

We are delighted to inform you that, day by day, more developers are recognising the importance of adding support for multi-currency environments to their plugins. When we released our plugin, the WooCommerce Currency Switcher, in 2013, we were pioneers in this field. At the time, not only there wasn’t any solution to make WooCommerce truly multi-currency, but there was nobody interested in developing one, either.

At the time, we were told by many developers that supporting multiple currencies was “impossible“, that there was no way to make the shop work correctly with more than one currency, and that no merchant would ever be interested in having such feature on their site. We are proud to say that we proved them wrong.

The ever-growing popularity of our Currency Switcher, and our other internationalisation solutions, such as Prices by Country, Tax Display by Country, and EU VAT Assistant, is now attracting the interest of many developers, who regularly contact us to see how they can extend their solutions to support multi-currency environments. As always, we are happy to help our colleagues in their endeavours, and pleased to see that so many want to join our project.

Two (and a half) more plugins join the multi-currency world

As the title indicates, we are happy to announce that two (and a half) more plugins have now been updated to support out multi-currency solution:

  • WooCommerce Multiple Free Gift This plugin allows you to easily grant gifts to your customers, based on flexible, custom criteria. Rules such as “buy X, get Y free“, or “free gifts with any purchase” can be created easily, and applied to your customer’s cart automatically. We would like to thank its author, Ankit Pokhrel, for the good job he did, testing and extending his plugin together with our Currency Switcher to achieve maximum compatibility.
  • WooCommerce Role Based Price This is a great plugin for the merchant who is dealing with different types of customers. As the name indicates, the Role Based Price plugin allows to sell products at different prices, depending on the role held by a customer. Wholesalers, consumers, VIP clients, they can all get their own, dedicated price.The integration with our Currency Switcher now allows you to enter such prices ineach of the currencies you enabled, greatly increasing your pricing options.We would like to thank Varun Sridharan for the effort he put into adding multi-currency support to his plugin. He is a great example of dedication, and his excellent work reflects that.
  • WooCommerce Product Fees This is the “half” plugin that we mentioned at the beginning of the paragraph. The reason why we call it “half” will be clear shortly.The WooCommerce Product Fees plugin was released on the 25th August 2015 by Caleb Burks, a member of WooThemes Support Team and, less than 24 hours later, we had extended it with full support for multiple currencies. Our integration added support for per-currency product fees, with automatic conversions as a fallback, while still maintaining full backward compatibility with single-currency environments.The above took us less than two hours of work, which is a great indicator of how easy it is to interface with our multi-currency solution.

    Why “half” plugin?
    Unfortunately, the author of the WooCommerce Product Fees plugin informed that, although our integration worked perfectly, he deemed it not to be important enough to be included in the main release. He reckoned that it would add unnecessary complexity, therefore he decided to leave the integration out for the moment, and to review it at a later stage. We respectfully disagree with such decision, for two reasons:

    1. Our extension required very few changes in the original code, and it doesn’t make the plugin much more complex.
    2. It’s easier to “think multi-currency” from the beginning of a plugin’s development, rather than try to “retrofit” such feature in a more complex product months, or years later.

    Of course, we do not want to enforce our vision and goals on anybody. We believe in collaboration, and freedom of choice is of utmost importance to us. We limited ourselves to explaining in detail why we believe that our integration should be part of the Product Fees plugin, and we will be happy to help Caleb in implementing it in the future. In the meantime, if you would like how a multi-currency aware of Product Fees plugin could work, you can get it from our Github fork: https://github.com/aelia-co/WooCommerce-Product-Fees.

    Important: please note that we only extended the first version of the plugin, which might have now been updated by its author. If you download the latest version of the Product Fees plugin, you will probably have to re-apply our changes to it.

Acknowledgements

We do understand that, despite one’s best effort, it’s not always viable to extend an existing product to work seamlessly in a multi-currency environment, and we appreciate all the effort put into it, no matter the final outcome. We would like to take the opportunity to extend our thanks to all the developers who worked on an integration, whether they decided to complete it or not. Thanks to all of you for your continued support and contributions!

The Aelia Team

news icon

WooCommerce 2.4 – Product Compatibility Status

WooCommerce 2.4 was released on the 8th of August 2015. As it always happens, the WooCommerce team released a couple of updates shortly after the main update. We started our testing process when WooCommerce 2.4 Beta2 became available, to ensure that our plugins would be compatible with the new version as soon as it became available.

As of today, we haven’t encountered specific issues, but we will keep running more tests, to check if any unexpected and/or undocumented breaking change was introduced, like it happened with WooCommece 2.3.

Important

We strongly recommend to install WooCommerce 2.4 on a test site first, and check that all installed plugins are working correctly, before updating your live site.

Compatibility status

Currency Switcher

We are addressing an issue related to an undocumented breaking change in WooCommerce, which may cause variable products to be displayed with wrong prices. We will release an update shortly to address this bug.

Our flagship product, the WooCommerce Currency Switcher, has been updated to version 3.7.8.150810, to address an issue caused by a new price caching logic. If you are running an older version, simply download and install the update using the link you received with your order, or from the My Account section on our site, and everything should work fine.

Currency Switcher Add-ons

Tax Display by Country

Compatible. The changes added to WooCommerce 2.4.x should not affect this product.

Prices by Country

Compatible since version 1.6.5.150811. Previous versions may display incorrect prices on variable products, due to the same issue that affected our Currency Switcher.

Payment Gateways

EU VAT Assistant

Compatible.

Blacklister

Testing in progress. This plugin does not include features that should be affected by the changes in WooCommerce 2.4.

We will keep testing our products to make sure that any issue which might still exist is fixed quickly and efficiently. Should you find any, please feel free to report it using our support portal: Aelia Support Portal. Thanks for your time and collaboration.

The Aelia Team