Skip to content
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

Fix formatting product when variation has no attributes #372

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

tomalec
Copy link
Member

@tomalec tomalec commented Mar 7, 2024

Changes proposed in this Pull Request:

quick-fix formatting product when variation has no attributes

Address #371

I was not able to reproduce it using UI, but according to #371 there is a chance to get woocommerce_add_to_cart fired for a product with $variation other than false but with no attributes.

Checks:

  • Does your code follow the WordPress coding standards?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Screenshots:

Detailed test instructions:

  1. ?
  2. Mock it by adding $variation = [] to

Additional details:

Changelog entry

Fix - adding variable product attributes.

@github-actions github-actions bot added changelog: fix Took care of something that wasn't working. type: bug The issue/PR is a confirmed bug. labels Mar 7, 2024
@@ -230,7 +230,7 @@ public function get_formatted_product( WC_Product $product, $variation = false )
$variation = $product->get_attributes();
}

if ( false !== $variation ) {
if ( false !== $variation && is_array( $variation ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just having if ( is_array( $variation ) ) would be sufficient, so we can remove the false !== $variation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the variation function param completely.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brought back the $variation, so we'd use it for non-"variation" producs

@tomalec tomalec marked this pull request as ready for review March 7, 2024 12:59
add a bit more elaborate code comment.
Copy link
Contributor

@jorgemd24 jorgemd24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! LGTM!

@tomalec tomalec merged commit 7d0cc53 into trunk Mar 7, 2024
5 checks passed
@tomalec tomalec deleted the fix/371-variable-product branch March 7, 2024 17:22
@jorgemd24 jorgemd24 mentioned this pull request Mar 7, 2024
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: fix Took care of something that wasn't working. type: bug The issue/PR is a confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants