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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-issue-36668
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

No warning shown for zero price.
12 changes: 7 additions & 5 deletions plugins/woocommerce/includes/admin/wc-admin-functions.php
Expand Up @@ -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! 😄

"
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 >= 0
AND meta_value != ''
"
);
// phpcs:enable WordPress.DB.PreparedSQL.NotPrepared

if ( 0 < ( $variation_count - $invalid_variation_count ) ) {
$invalid_variation_count = $variation_count - $valid_variation_count;

if ( 0 < $invalid_variation_count ) {
?>
<div id="message" class="inline notice notice-warning woocommerce-message woocommerce-notice-invalid-variation">
<p>
<?php
echo wp_kses_post(
sprintf(
/* Translators: %d variation count. */
_n( '%d variation does not have a price.', '%d variations do not have prices.', ( $variation_count - $invalid_variation_count ), 'woocommerce' ),
( $variation_count - $invalid_variation_count )
_n( '%d variation does not have a price.', '%d variations do not have prices.', $invalid_variation_count, 'woocommerce' ),
$invalid_variation_count
) . '&nbsp;' .
__( 'Variations (and their attributes) that do not have prices will not be shown in your store.', 'woocommerce' )
);
Expand Down