WC_Product_Attribute::get_variation() returns true for product attributes of simple products
#37.879 aberto em 20 de abr. de 2023
Description
Prerequisites
- I have carried out troubleshooting steps and I believe I have found a bug.
- I have searched for similar bugs in both open and closed issues and cannot find a duplicate.
Describe the bug
Hey guys,
-
add a new (custom) product attribute to an existing simple product
-
try this code:
add_action( 'wp', function() {
$product = wc_get_product( 8439 );
$attributes = $product->get_attributes();
echo '<pre>';
var_dump( $attributes );
echo '</pre>';
exit();
});
you get:
array(2) {
["pa_color"]=>
object(WC_Product_Attribute)#1710 (1) {
["data":protected]=>
array(6) {
["id"]=>
int(2)
["name"]=>
string(8) "pa_color"
["options"]=>
array(4) {
[0]=>
int(187)
[1]=>
int(193)
[2]=>
int(189)
[3]=>
int(194)
}
["position"]=>
int(0)
["visible"]=>
bool(true)
["variation"]=>
bool(false)
}
}
["test"]=>
object(WC_Product_Attribute)#1702 (1) {
["data":protected]=>
array(6) {
["id"]=>
int(0)
["name"]=>
string(4) "Test"
["options"]=>
array(3) {
[0]=>
string(3) "One"
[1]=>
string(3) "Two"
[2]=>
string(5) "Three"
}
["position"]=>
int(1)
["visible"]=>
bool(true)
["variation"]=>
bool(true)
}
}
}
new attributes will always get variation => true. In the past, it was "false", which makes more sense for simple products
Expected behavior
$attribute->get_variation() should always return false for simple products
Actual behavior
for a new added attribute $attribute->get_variation() returns true for simple products
Steps to reproduce
see above
WordPress Environment
WordPress Environment
WordPress address (URL): Site address (URL): WC Version: 7.7.0 REST API Version: ✔ 7.7.0 WC Blocks Version: ✔ 10.0.1 Action Scheduler Version: ✔ 3.5.4 Log Directory Writable: ✔ WP Version: 6.2 WP Multisite: – WP Memory Limit: 5 GB WP Debug Mode: ✔ WP Cron: ✔ Language: en_US External object cache: –
Server Environment
Server Info: Apache PHP Version: 8.1.18 PHP Post Max Size: 200 MB PHP Time Limit: 1000 PHP Max Input Vars: 1000 cURL Version: 7.74.0 OpenSSL/1.1.1n
SUHOSIN Installed: – MySQL Version: 10.5.18-MariaDB-0+deb11u1 Max Upload Size: 200 MB Default Timezone is UTC: ✔ fsockopen/cURL: ✔ SoapClient: ✔ DOMDocument: ✔ GZip: ✔ Multibyte String: ✔ Remote Post: ✔ Remote Get: ✔
Security
Secure connection (HTTPS): ✔ Hide errors from visitors: ✔
Active Plugins (2)
WooCommerce Beta Tester: by WooCommerce – 2.1.0 WooCommerce: by Automattic – 7.7.0-beta.1
Settings
API Enabled: ✔ Force SSL: – Currency: EUR (€) Currency Position: right_space Thousand Separator: . Decimal Separator: , Number of Decimals: 2 Taxonomies: Product Types: bundle (bundle) composite (composite) external (external) grouped (grouped) simple (simple) subscription (subscription) variable (variable) variable subscription (variable-subscription)
Taxonomies: Product Visibility: exclude-from-catalog (exclude-from-catalog) exclude-from-search (exclude-from-search) featured (featured) outofstock (outofstock) rated-1 (rated-1) rated-2 (rated-2) rated-3 (rated-3) rated-4 (rated-4) rated-5 (rated-5)
Connected to WooCommerce.com: – Enforce Approved Product Download Directories: – HPOS feature screen enabled: – HPOS feature enabled: – Order datastore: WC_Order_Data_Store_CPT HPOS data sync enabled: –
WC Pages
Shop base: #7446 - /shop/ Cart: #7447 - /warenkorb/ Checkout: #11714 - /kasse/ My account: #7449 - /mein-konto/ Terms and conditions: #20000222 - /allgemeine_geschaeftsbedingungen/
Theme
Name: Twenty Twenty-One Version: 1.8 Author URL: https://wordpress.org/ Child Theme: ❌ – If you are modifying WooCommerce on a parent theme that you did not build personally we recommend using a child theme. See: How to create a child theme WooCommerce Support: ✔
Templates
Overrides: –
Admin
Enabled Features: activity-panels analytics coupons customer-effort-score-tracks import-products-task experimental-fashion-sample-products shipping-smart-defaults shipping-setting-tour homescreen marketing mobile-app-banner navigation onboarding onboarding-tasks remote-inbox-notifications remote-free-extensions payment-gateway-suggestions shipping-label-banner subscriptions store-alerts transient-notices woo-mobile-welcome wc-pay-promotion wc-pay-welcome-page
Disabled Features: product-block-editor minified-js new-product-management-experience product-variation-management settings
Daily Cron: ✔ Next scheduled: 2023-04-20 12:42:06 +02:00 Options: ✔ Notes: 49 Onboarding: completed
Status report information
Generated at: 2023-04-20 11:54:39 +02:00
Isolating the problem
- I have deactivated other plugins and confirmed this bug occurs when only WooCommerce plugin is active.
- This bug happens with a default WordPress theme active, or Storefront.
- I can reproduce this bug consistently using the steps above.