-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Please consider adding back the woocommerce_product_default_attributes
filter
#19814
Comments
You can use the filter So no need to add back |
@lomars thanks so much, this works! The 2 arguments are even the same like for the old filter, so in fact it looks like it was more or less just renamed. FWIW, I find it strange that this filter can neither be found on GitHub nor on the hooks API docs. That's and also with DDG is where I search for 1h or so without finding... I'll change the subject, so maybe to docs could be made to include this filter, too. |
Explanations:Since Woocommerce 3 and new introduced CRUDS setter methods, when a method is using See this line woocommerce/includes/abstracts/abstract-wc-data.php Lines 600 to 623 in b2e4052
and this line woocommerce/includes/abstracts/abstract-wc-data.php Lines 590 to 598 in b2e4052
So the filter hook is dynamically made this way (where with 2 arguments:
Related update on StackOverFlow |
There used to be a
woocommerce_product_default_attributes
filter for the default variation attributes. I used this in 2.6 for programatically selecting a certain a certain product variation. (e.g. 3 different variants, but 2 of them are sold out, so we select the only one being not sold out).This filter does not work anymore in WC 3 since it has been move to a deprecated method that is not called any more from core:
woocommerce/includes/legacy/abstract-wc-legacy-product.php
Lines 157 to 166 in 3522857
I cannot find any upgrade, migration or changelog notes on how to do handle the removal of this filter.
At Stackoverflow a user suggests to use the
woocommerce_before_add_to_cart_form
action to get the default variation, mangle it and then set them back to the product. This seems overly complicated and a filter should be there for this.Would you consider adding the old
woocommerce_product_default_attributes
or a filter with a new name back to eitherpublic function get_variation_default_attributes()
:woocommerce/includes/class-wc-product-variable.php
Lines 235 to 240 in d5e98e8
or
get_default_attributes()
:woocommerce/includes/abstracts/abstract-wc-product.php
Lines 526 to 535 in 28a4e88
?
Otherwise I'll go down the
action
road but as said there should be a filter for this.The text was updated successfully, but these errors were encountered: