Support » Plugin: WooCommerce Direct Variation Link » WC3.0 compatibility issue

  • In WC3.0 the filter being used here was deprecated.
    I thought I’d share my findings to help others here.

    If after updating to wc3.0 you find this doesn’t work, change line 19 from
    add_filter(‘woocommerce_product_default_attributes’, ‘setup_swatches’, 10, 1);
    add_filter(‘woocommerce_product_get_default_attributes’, ‘setup_swatches’, 10, 1);


Viewing 9 replies - 1 through 9 (of 9 total)
  • Another quick note, I needed to wrap the $product->get_variation_attributes() with a is_object check otherwise the admin product edit screen would fatal making product attributes uneditable.

    thanks joel!



    Thanks Joel. Any chance you can show exactly how you’re using the “is_object check”? What lines are modified, etc.?

    I’ve tried wrapping $product->get_variation_attributes() (around line 45) but I’m still receiving an error on the product edit page. I also tried an if(is_object()) statement with no luck. Then again, I really don’t know what I’m doing.

    Thanks. These seem like pretty easy fixes for one that knows what they’re doing — maybe the developer will see and update?!



    I couldn’t this it to work using “is_object()”. I kept getting an error on the product edit page — something like “Fatal error: Call to a member xxx on null woocommerce”.

    What is working for me is to wrap the code in both functions with “if(product != null)”.

    My changes:

    Not a programmer, so the above changes may not be the correct or ideal way to do this.

    Júlio Reis


    Hi @bryanobx – I think instead of checking whether $product is not null, you should use the new WooCommerce 3.0.0 function WC_Product_Variable::get_variation_attributes instead.

    So, instead of

    global $product;
    $available_variations = $product->get_variation_attributes();

    You just do

    $available_variations = WC_Product_Variable::get_variation_attributes();

    And do it twice in the code.

    I found out about the new function here:

    Note: I haven’t tested this yet, please proceed with caution.

    Júlio Reis


    Please disregard my previous comment… not working! @bryanobx‘s changes work perfectly though.

    Thanks to both joelwarren and bryanobx. I was able to get this to work using your suggestions.

    And here’s one of my own:
    If your attributes and values contain multiple words, the ‘+’ feature only partially works. The URL parameters you use ARE case sensitive, and the lowercase translation does not work as you are led to believe. According to the description, this should have worked:

    I had to make the following changes to the URL to make the plugin work:

    (notice the capitalized 1st letter of each word)

    I forked it here for those who don’t want to bother with code editing

    @bheadrick or @joelwarren

    Any chance you can look at this and fix an issue?

    Example taken from a post by @mcnitefly
    When you have a product with two attributes: color and size and I use one GET parameter in the URL, “color”, the link that gets created is correct and points to the product variation of the correct color. But the other attribute – size in this example – needs to be selected, too and is not. (Gets set to “Choose an option”)

    WooCommerce has the option to set default parameters for the attributes. Keeping these parameters would solve the issue – but the link that gets created by “WooCommerce Direct Variation Link” seems to overwrite these default parameters. Even the ones that where not addressed by the URL created.

    • This reply was modified 1 year, 10 months ago by  RobertGomez. Reason: added @joelwarren
Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘WC3.0 compatibility issue’ is closed to new replies.