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);
    to
    add_filter(‘woocommerce_product_get_default_attributes’, ‘setup_swatches’, 10, 1);

    Cheers,
    Joel

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:
    https://pastebin.com/4D3sTw9K

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

    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: http://woocommerce.wp-a2z.org/oik_api/wc_product_variableget_variation_attributes/

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

    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:

    yoursite.com/product/yourproductname/?attribute1=word1+word2&attribute2=word3+word4+word5

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

    yoursite.com/product/yourproductname/?attribute1=Word1+Word2&attribute2=Word3+Word4+Word5

    (notice the capitalized 1st letter of each word)

    bheadrick

    (@bheadrick)

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

    https://github.com/BHEADRICK/woocommerce-direct-variation-link

    @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 11 months, 3 weeks 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.