Skip to content

fix typo when calling wc_format_decimal function #60288

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

masteradhoc
Copy link
Contributor

@masteradhoc masteradhoc commented Aug 10, 2025

Submission Review Guidelines:

Changes proposed in this Pull Request:

  • fix typo when calling wc_format_decimal function

Closes #60287 .

(For Bug Fixes) Bug introduced in PR #54399.

How to test the changes in this Pull Request:

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

  1. go to wp-admin area and select products
  2. choose a variable product
  3. set a COGS value (test different values) for the variable product and save it
  4. see if everything gets saved correctly

Testing that has already taken place:

Changelog entry

  • Automatically create a changelog entry from the details below.
  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Fix - Fixes an existing bug
  • Add - Adds functionality
  • Update - Update existing functionality
  • Dev - Development related task
  • Tweak - A minor adjustment to the codebase
  • Performance - Address performance issues
  • Enhancement - Improvement to existing functionality

Message

Changelog Entry Comment

Comment

@github-actions github-actions bot added type: community contribution plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Aug 10, 2025
Copy link
Contributor

coderabbitai bot commented Aug 10, 2025

📝 Walkthrough

Walkthrough

A function call within the WooCommerce product data meta box code was corrected by changing the function name from wc_format_Decimal to wc_format_decimal when formatting the cost of goods sold (COGS) value for product variations. No other logic or control flow was modified.

Changes

Cohort / File(s) Change Summary
Function Name Correction
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
Corrected function call from wc_format_Decimal to wc_format_decimal for COGS value formatting.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1)

572-578: Confirm no remaining casing issues and add regression test for COGS

Verified that there are no occurrences of the incorrectly cased function wc_format_Decimal in the repository. Next, please add or extend a regression test to cover saving a variable product with variable_cost_value set, asserting that:

  • No fatal errors occur during save.
  • The COGS value is persisted correctly on the variation.

• Suggestion: In your PHPUnit (or E2E) test suite, create a test under tests/unit (or the appropriate integration folder) that:

  1. Creates a variable product with at least one variation.
  2. Sets $_POST['variable_cost_value'][0] to a decimal string (e.g., “12.34”).
  3. Triggers the product save routine.
  4. Retrieves the saved variation and asserts get_cogs_value() returns the expected float.

Let me know if you’d like a draft test example.

🧹 Nitpick comments (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1)

418-421: Optional: DRY COGS value parsing to prevent future typos and keep behavior consistent.

Both blocks parse and set COGS similarly. Consider a tiny private helper (e.g., parse_decimal_or_null($raw)) to centralize sanitize/empty handling and call wc_format_decimal once. This reduces the chance of future casing typos and keeps behavior uniform.

Example sketch (outside the selected ranges, for illustration):

// Inside WC_Meta_Box_Product_Data
private static function parse_decimal_or_null( $raw ) {
	$val = wc_clean( wp_unslash( $raw ) );
	if ( '' === $val || is_null( $val ) ) {
		return null;
	}
	return (float) wc_format_decimal( $val );
}

Then within the two spots:

  • Product-level: $product->set_cogs_value( self::parse_decimal_or_null( $_POST['_cogs_value'] ?? null ) );
  • Variation-level: $variation->set_cogs_value( self::parse_decimal_or_null( $_POST['variable_cost_value'][ $i ] ?? '' ) );

Also applies to: 572-578

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62f844a and 81408d8.

📒 Files selected for processing (1)
  • plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{php,js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/code-quality.mdc)

**/*.{php,js,jsx,ts,tsx}: Guard against unexpected inputs
Sanitize and validate any potentially dangerous inputs
Ensure code is backwards compatible
Write code that is readable and intuitive
Ensure code has unit or E2E tests where applicable

Files:

  • plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
**/*.{php,js,ts,jsx,tsx}

⚙️ CodeRabbit Configuration File

**/*.{php,js,ts,jsx,tsx}: Don't trust that extension developers will follow the best practices, make sure the code:

  • Guards against unexpected inputs.
  • Sanitizes and validates any potentially dangerous inputs.
  • Is backwards compatible.
  • Is readable and intuitive.
  • Has unit or E2E tests where applicable.

Files:

  • plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
🧠 Learnings (2)
📓 Common learnings
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.
📚 Learning: 2025-06-17T07:07:53.443Z
Learnt from: samueljseay
PR: woocommerce/woocommerce#58716
File: plugins/woocommerce/client/blocks/assets/js/blocks/mini-cart/iapi-frontend.ts:83-101
Timestamp: 2025-06-17T07:07:53.443Z
Learning: In WooCommerce blocks, when porting existing code patterns that have known issues (like parseInt truncating decimal money values), maintain consistency with existing implementation rather than making isolated fixes. The preference is for systematic refactoring approaches (like broader Dinero adoption) over piecemeal changes.

Applied to files:

  • plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php
🔇 Additional comments (1)
plugins/woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-data.php (1)

577-577: Fatal fix: Correct function name used (wc_format_decimal).

Good catch. This removes the fatal during variation save by calling the correct helper. Matches the product-level usage earlier in this file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin. type: community contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CodeRabbitAI found typo in class-wc-meta-box-product-data.php
1 participant