• Resolved Diego

    (@daigo75)


    Background
    We developed a plugin that extends shipping methods, such as flat rate and free shipping, adding extra features to them. This is done by creating subclasses of the original shipping classes. The subclasses are 100% backward compatible, so any consumer can just use them as if they were the original ones. This works fine, but it causes a small issue with the Amount Left for Free Shipping plugin.

    Issue
    The Amount Left for Free Shipping plugin checks for the presence of a free shipping method by checking that the class is exactly WC_Shipping_Free_Shipping. Since the subclass is different, the check fails and the ALFS plugin ignores the shipping method, even though it is a “free shipping” one.

    Fix
    The fix is simple, it involves changing the check, as follows:
    1. Open file amount-left-free-shipping-woocommerce/includes/alg-wc-left-to-free-shipping-functions.php
    2. Replace the following line:

    if ( 'WC_Shipping_Free_Shipping' === get_class( $shipping_method ) ) {

    with this:

    if ( $shipping_method instanceof \WC_Shipping_Free_Shipping ) {

    This changes the check from “shipping method is exactly WC_Shipping_Free_Shipping” to a more flexible “shipping method is WC_Shipping_Free_Shipping, or derived from it“. The new check allows to accept any free shipping method derived from the original ones, while retaining the rest of the existing logic.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Suggestion – Improving compatibility’ is closed to new replies.