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/issue 36668: Shows warning only when the variation price is empty #37817

Merged
merged 2 commits into from Apr 19, 2023

Conversation

iyut
Copy link
Contributor

@iyut iyut commented Apr 19, 2023

Submission Review Guidelines:

Changes proposed in this Pull Request:

This PR is to fix issue for a warning that being displayed when user put 0 price for product variation.
To fix that, I changed the condition in sql to be like this :

SELECT count(post_id) FROM {$wpdb->postmeta}
WHERE post_id in (" . implode( ',', array_map( 'absint', $variation_ids ) ) . ")
AND ( meta_key='_subscription_sign_up_fee' OR meta_key='_price' )
AND meta_value >= 0
AND meta_value != ''

By doing this, it allows the user to set the price with 0.

Closes #36668 .

How to test the changes in this Pull Request:

Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:

  1. Create a new variable product.

  2. Set two new attributes for the product like the screenshot below :
    image

  3. Go to "Variations" tab and click "Generate variations".

  4. Add the regular price for the first variant with 0 and the other variants with any number but more than 0.
    image

image

  1. Click "Save Changes" to save the variations.

  2. Notice that no Warning being displayed.

  3. Now, empty the regular price for the first variant and click "Save Changes".
    image

  4. Notice that the warning being displayed :
    image

@iyut iyut changed the title Fix/issue 36668 Fix/issue 36668: Shows warning only when the variation price is empty Apr 19, 2023
@woocommercebot woocommercebot requested review from a team and barryhughes and removed request for a team April 19, 2023 09:39
@github-actions github-actions bot added the plugin: woocommerce Issues related to the WooCommerce Core plugin. label Apr 19, 2023
@mattsherman mattsherman self-requested a review April 19, 2023 14:35
@mattsherman
Copy link
Contributor

I'll review this

@mattsherman mattsherman removed the request for review from barryhughes April 19, 2023 14:39
Copy link
Contributor

@mattsherman mattsherman left a comment

Choose a reason for hiding this comment

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

Nice work on this @iyut!

In addition to fixing the issue, the code is now much clearer, thanks to your naming of $invalid_variation_count to $valid_variation_count.

@@ -508,27 +508,29 @@ function wc_render_invalid_variation_notice( $product_object ) {

// Check if a variation exists without pricing data.
// phpcs:disable WordPress.DB.PreparedSQL.NotPrepared
$invalid_variation_count = $wpdb->get_var(
$valid_variation_count = $wpdb->get_var(
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for fixing this up... it was so confusing that this was incorrectly named $invalid_variation_count previously! Most of my time reviewing this was just making sure that I wasn't missing something with this obvious of a misname! 😄

@mattsherman mattsherman merged commit e0049fe into woocommerce:trunk Apr 19, 2023
18 of 23 checks passed
@github-actions github-actions bot added this to the 7.8.0 milestone Apr 19, 2023
@iyut
Copy link
Contributor Author

iyut commented Apr 26, 2023

Hi @mattsherman , just wanted to say thanks for reviewing this PR 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No price variation warning shows for zero priced variations.
4 participants