Skip to content

Fix: Display term names instead of term IDs for product_cat and product_shipping_class on product page - #1649

Open
arifulhoque7 wants to merge 12 commits into
weDevsOfficial:developfrom
arifulhoque7:fix/product-meta-display-term-labels
Open

Fix: Display term names instead of term IDs for product_cat and product_shipping_class on product page#1649
arifulhoque7 wants to merge 12 commits into
weDevsOfficial:developfrom
arifulhoque7:fix/product-meta-display-term-labels

Conversation

@arifulhoque7

@arifulhoque7 arifulhoque7 commented Jul 28, 2025

Copy link
Copy Markdown
Contributor
  • New Features

    • Enhanced support for WooCommerce taxonomies, including improved handling of product categories, tags, shipping classes, and attributes.
    • Automatic creation and assignment of missing WooCommerce terms during product updates.
  • Bug Fixes

    • Improved data consistency and reliability through stricter type comparisons and better data normalization.
  • Refactor

    • Streamlined taxonomy and attribute handling for WooCommerce products, resulting in more predictable and safer behavior.

Summary by CodeRabbit

  • New Features

    • Enhanced product attribute display with custom form-based labels for WooCommerce products
    • Improved support for product taxonomies including categories, tags, and shipping classes
  • Bug Fixes

    • Strengthened validation checks for reCAPTCHA verification
    • Better product attribute metadata handling and WooCommerce product data synchronization

@arifulhoque7
arifulhoque7 requested a review from sapayth July 28, 2025 03:44
@arifulhoque7 arifulhoque7 self-assigned this Jul 28, 2025
@coderabbitai

coderabbitai Bot commented Jul 28, 2025

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

FieldableTrait is refactored to add WooCommerce-aware taxonomy normalization in get_input_fields(), a heavily restructured set_custom_taxonomy() that delegates to new WooCommerce/regular handlers and syncs _product_attributes, a rewritten woo_attribute(), and two new public methods for WooCommerce attribute display filtering. A new woocommerce-attribute-labels.php file customizes attribute labels via post meta. Frontend_Form constructor wires the new hooks.

Changes

WooCommerce Taxonomy & Attribute Integration

Layer / File(s) Summary
Input field normalization and strict comparison fixes
includes/Traits/FieldableTrait.php
get_input_fields() normalizes WooCommerce taxonomy names/flags for product_cat, product_tag, and product_shipping_class with strict comparisons. on_edit_no_check_recaptcha(), validate_re_captcha(), and prepare_meta_fields() switch to strict equality for captcha modes, invisible reCAPTCHA success, address array checks, and ACF option comparisons.
set_custom_taxonomy refactor and woo_attribute rewrite
includes/Traits/FieldableTrait.php
set_custom_taxonomy() is restructured with WooCommerce-aware orchestration: applies default terms, stores taxonomy labels in _wpuf_taxonomy_labels post meta, routes processing through handle_woocommerce_taxonomy() vs handle_regular_taxonomy(), accumulates _product_attributes payload, runs WooCommerce sync/cache clearing, and defaults product type to simple. woo_attribute() is rewritten to exclude product_cat/product_tag/product_brand, convert term IDs to display names, and prioritize form-field labels.
WooCommerce display hooks and attribute label file
includes/Traits/FieldableTrait.php, includes/Frontend/Frontend_Form.php, includes/functions/woocommerce-attribute-labels.php, wpuf-functions.php
init_woocommerce_hooks() registers a filter on woocommerce_display_product_attributes; filter_woocommerce_product_attributes() strips main taxonomies/brand, applies form-based labels, strips HTML, and converts values to term names. Frontend_Form constructor conditionally calls init_woocommerce_hooks(). New wpuf_customize_woocommerce_attribute_labels() reads _wpuf_taxonomy_labels from post meta and falls back to default labels for WooCommerce system taxonomies.
Whitespace-only edits
includes/Ajax/Frontend_Form_Ajax.php
Two blank lines inserted in submit_post and send_mail_for_guest. No behavior change.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested labels

QA Approved, Ready to Merge

Suggested reviewers

  • sapayth

Poem

🐇 Hop hop, the attributes align,
WooCommerce labels now clearly shine!
Taxonomies sorted, strict equals too,
_wpuf_taxonomy_labels brand new.
A rabbit reviewed every term name,
Product attributes will never be the same! 🛒

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses a core aspect of the changeset—displaying term names instead of IDs for product categories and shipping classes—which is a primary focus of the WooCommerce taxonomy handling refactoring.
Docstring Coverage ✅ Passed Docstring coverage is 92.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
includes/Traits/FieldableTrait.php (1)

512-512: Fix formatting: Add space before is_wp_error.

-if ( !is_wp_error($new_term) ) {
+if ( ! is_wp_error( $new_term ) ) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b56e6a6 and cb7d3e5.

📒 Files selected for processing (1)
  • includes/Traits/FieldableTrait.php (11 hunks)
🧰 Additional context used
🪛 GitHub Actions: Inspections
includes/Traits/FieldableTrait.php

[warning] 1-1: This comment is 64% valid code; is this commented out code?


[error] 1-1: Opening parenthesis of a multi-line function call must be the last content on the line

🔇 Additional comments (8)
includes/Traits/FieldableTrait.php (8)

119-183: Good implementation of WooCommerce taxonomy handling.

The strict type comparisons and WooCommerce-specific taxonomy normalization are well implemented. The normalization of product_category to product_cat correctly handles variations in taxonomy naming, and the addition of the is_woocommerce flag enables proper downstream processing.


222-225: Appropriate use of strict comparisons for reCAPTCHA type checking.

The change from loose to strict comparisons for reCAPTCHA type checking improves type safety and prevents potential type coercion issues.


279-311: Excellent security improvement with strict comparison for reCAPTCHA validation.

The strict comparisons, particularly true !== $response['success'] at line 311, ensure proper boolean validation without type coercion, which is crucial for security checks.


458-661: Excellent refactoring of taxonomy handling that addresses the PR objective.

This comprehensive refactoring properly handles the conversion of term IDs to term names for display, which directly addresses the issue mentioned in the PR title. The implementation correctly:

  1. Handles both numeric IDs and string names for product categories
  2. Converts term IDs to names for product tags
  3. Provides special handling for shipping classes including empty value scenarios
  4. Maintains compatibility with both hierarchical and non-hierarchical taxonomies

721-807: Consistent application of strict comparisons in meta field preparation.

The strict type comparisons ensure accurate field type checking and configuration value comparisons.


860-908: Well-implemented term ID to name conversion for WooCommerce attributes.

The rewritten method correctly:

  • Skips product categories which are handled elsewhere
  • Converts term IDs to their display names
  • Creates missing terms when necessary
  • Returns properly formatted attribute data for WooCommerce

This directly supports the PR objective of displaying term names instead of IDs.


839-839: Appropriate use of strict comparison in array search.

Using strict comparison ensures exact value matching without type coercion, which is important for accurate search results.


453-908: Verify the fix displays term names correctly on the product page.

The implementation looks solid and should resolve the issue of displaying term IDs instead of names. Please ensure to test the following scenarios:

  1. Product categories display names instead of IDs
  2. Shipping classes display names instead of IDs
  3. Product tags and attributes show proper names
  4. Terms are correctly created when they don't exist

@arifulhoque7 arifulhoque7 added needs: dev review This PR needs review by a developer needs: testing labels Jul 28, 2025
Comment thread includes/Traits/FieldableTrait.php Outdated
$tax = [ $tax ];
// Handle other WooCommerce taxonomies if WooCommerce is enabled
if ( $is_woo_taxonomy && (
'pa_' === substr( $taxonomy_name, 0, 3 ) ||

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do not check this way. use This taxonomy is a WooCommerce attribute option from form builder field setting

@sapayth sapayth added needs: author reply This PR needs author feedback or code changes and removed needs: dev review This PR needs review by a developer labels Jul 30, 2025
@arifulhoque7 arifulhoque7 reopened this Jul 30, 2025
@arifulhoque7 arifulhoque7 added needs: dev review This PR needs review by a developer and removed needs: author reply This PR needs author feedback or code changes labels Jul 30, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
includes/Traits/FieldableTrait.php (1)

474-474: Consider using form builder field setting for WooCommerce attribute detection.

Based on a previous review comment, consider using the "This taxonomy is a WooCommerce attribute" option from the form builder field setting instead of checking the woo_attr field directly.

🧹 Nitpick comments (1)
includes/Traits/FieldableTrait.php (1)

453-661: Comprehensive WooCommerce taxonomy improvements with refactoring opportunity.

The enhanced taxonomy handling significantly improves WooCommerce support with proper term creation, ID/name conversion, and attribute management. The logic is sound and handles edge cases well.

However, the method has become quite complex. Consider breaking it into smaller, focused methods for better maintainability:

private function handle_woo_product_categories($post_id, $posted_terms) { /* ... */ }
private function handle_woo_product_tags($post_id, $posted_terms) { /* ... */ }
private function handle_standard_taxonomy($post_id, $taxonomy, $posted_terms) { /* ... */ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb7d3e5 and fe651d1.

📒 Files selected for processing (1)
  • includes/Traits/FieldableTrait.php (11 hunks)
🔇 Additional comments (5)
includes/Traits/FieldableTrait.php (5)

119-189: Excellent improvements to WooCommerce taxonomy handling!

The changes enhance type safety with strict comparisons and add comprehensive WooCommerce taxonomy support. The normalization of product_category to product_cat and the automatic flagging of WooCommerce taxonomies will improve consistency.


222-231: LGTM - Type safety improvements.

The strict equality comparisons for reCAPTCHA type checking enhance type safety and prevent potential type coercion issues.


279-314: LGTM - Enhanced type safety in reCAPTCHA validation.

The strict integer comparisons and boolean checks improve the reliability of reCAPTCHA validation logic.


721-721: LGTM - Consistent strict type comparisons.

The strict equality checks for string values improve type safety and consistency throughout the method.

Also applies to: 805-807


860-908: Excellent rewrite of WooCommerce attribute handling!

The method now properly:

  • Handles term ID to name conversion
  • Creates missing terms automatically
  • Skips product categories appropriately
  • Returns properly formatted WooCommerce attribute arrays

The logic is robust with good error handling and edge case management.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
includes/Traits/FieldableTrait.php (1)

474-521: Robust product category handling with term creation.

The logic properly handles both term IDs and names for product categories, creating missing terms automatically. This addresses the PR objective of improving WooCommerce taxonomy support.

Minor formatting issue on Line 512:

-                                if ( !is_wp_error($new_term) ) {
+                                if ( ! is_wp_error( $new_term ) ) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe651d1 and 165b87b.

📒 Files selected for processing (1)
  • includes/Traits/FieldableTrait.php (11 hunks)
🔇 Additional comments (12)
includes/Traits/FieldableTrait.php (12)

119-119: LGTM! Improved type safety with strict comparisons.

The change from loose (==) to strict (===) equality comparisons enhances type safety and prevents unexpected type coercion issues.

Also applies to: 131-131, 136-136, 159-159


164-183: Excellent WooCommerce taxonomy handling enhancement.

The new logic properly normalizes WooCommerce taxonomy names and sets appropriate flags:

  • Normalizes product_category to product_cat for consistency
  • Correctly identifies WooCommerce taxonomies with flags
  • Handles shipping class with proper hierarchical setting and default input type

This aligns well with the PR objectives to improve WooCommerce taxonomy support.


222-222: LGTM! Consistent type safety improvement.

The strict string comparisons for reCAPTCHA type validation maintain consistency with the broader type safety enhancements throughout the file.

Also applies to: 225-225


279-279: LGTM! Proper integer flag validation.

The strict integer comparisons for reCAPTCHA flags ensure exact value matching and prevent issues with truthy/falsy value interpretation.

Also applies to: 295-295, 304-304, 311-311


458-471: LGTM! Clean initialization and default term handling.

The new structure properly initializes variables and handles default terms when no terms are posted, improving the robustness of the taxonomy assignment process.


524-550: Excellent product tag handling with ID-to-name conversion.

The implementation correctly converts term IDs to names for product tags and handles both single and array inputs. This ensures proper WooCommerce tag assignment.


553-580: Comprehensive WooCommerce taxonomy and attribute handling.

The logic properly handles product attributes (pa_ prefix), shipping classes, and other WooCommerce taxonomies. The attribute metadata preparation for WooCommerce is correctly structured.


582-652: Well-structured regular taxonomy processing.

The implementation correctly differentiates between hierarchical and non-hierarchical taxonomies, handles text vs select inputs appropriately, and includes proper term creation logic. The WooCommerce attribute integration is seamless.


655-661: Proper WooCommerce attributes persistence.

The final step correctly updates the _product_attributes post meta when WooCommerce attributes are present, ensuring proper integration with WooCommerce's attribute system.


721-721: LGTM! Consistent type safety enhancement.

The strict string comparison for the multiple field check maintains consistency with the type safety improvements throughout the file.


805-805: LGTM! Type safety for ACF compatibility checks.

The strict string comparisons for address input type and ACF compatibility checks are appropriate and maintain consistency with the overall type safety improvements.

Also applies to: 807-807


862-908: WooCommerce attribute integration aligns with form builder settings

  • Field definitions in includes/Fields/Field_Contract.php declare the woo_attr ("This taxonomy is a WooCommerce attribute") and woo_attr_vis ("Visible on product page") options.
  • Admin template (includes/Admin/Forms/Template_Post.php) and front-end handler (includes/class-frontend-render-form.php) both check woo_attr === 'yes' before calling woo_attribute().
  • In FieldableTrait (includes/Traits/FieldableTrait.php), $is_woo_taxonomy is derived via wpuf_is_checkbox_or_toggle_on( $taxonomy['woo_attr'] ), and woo_attribute() respects woo_attr_vis for visibility.

The rewrite correctly leverages the form builder’s WooCommerce flag; no further changes required.

@sapayth sapayth added Dev Review Done and removed needs: dev review This PR needs review by a developer labels Jul 30, 2025
@Rubaiyat-E-Mohammad

Rubaiyat-E-Mohammad commented Jul 30, 2025

Copy link
Copy Markdown
Contributor

Could not built properly @arifulhoque7 vai
<img width="2092" height="682" alt="CleanShot 2025-07-30 at 19 05 44@2x" src="https://github.com/user-attachments/assets/f17b5728-2ae6-4a21-b3b3
CleanShot 2025-07-30 at 19 06 41@2x
-1f1547a7dd4f" />
CleanShot 2025-07-31 at 10 09 51

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added bug needs: dev review This PR needs review by a developer and removed needs: testing Dev Review Done labels Jul 30, 2025
@sapayth sapayth added Dev Review Done and removed needs: dev review This PR needs review by a developer labels Jul 31, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
includes/Frontend/Frontend_Form.php (1)

23-23: Remove trailing whitespace.

Static analysis detected trailing whitespace at the end of this line.

-        
+
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 165b87b and ef6b970.

📒 Files selected for processing (3)
  • includes/Ajax/Frontend_Form_Ajax.php (1 hunks)
  • includes/Frontend/Frontend_Form.php (1 hunks)
  • includes/Traits/FieldableTrait.php (11 hunks)
✅ Files skipped from review due to trivial changes (1)
  • includes/Ajax/Frontend_Form_Ajax.php
🧰 Additional context used
🧬 Code Graph Analysis (1)
includes/Frontend/Frontend_Form.php (1)
includes/Traits/FieldableTrait.php (1)
  • init_woocommerce_hooks (984-988)
🪛 GitHub Check: Run PHPCS inspection
includes/Frontend/Frontend_Form.php

[failure] 23-23:
Whitespace found at end of line

🔇 Additional comments (8)
includes/Frontend/Frontend_Form.php (1)

24-27: LGTM! Proper conditional initialization of WooCommerce hooks.

The conditional check ensures that WooCommerce hooks are only initialized when the method exists, following good defensive programming practices. This aligns well with the enhanced WooCommerce taxonomy support mentioned in the PR objectives.

includes/Traits/FieldableTrait.php (7)

119-119: LGTM! Consistent use of strict type comparisons.

The changes from loose to strict equality comparisons (===) improve type safety and reduce potential bugs from unexpected type coercion.

Also applies to: 131-131, 136-136, 159-159, 164-164


165-184: Excellent WooCommerce taxonomy normalization.

The added logic properly handles WooCommerce-specific taxonomies by:

  • Normalizing product_category to the correct product_cat taxonomy name
  • Flagging WooCommerce taxonomies with appropriate metadata
  • Setting correct defaults for shipping classes

This addresses the PR objective of improving WooCommerce taxonomy support.


222-222: LGTM! Improved reCAPTCHA validation with strict comparisons.

The changes from loose to strict equality comparisons in reCAPTCHA validation enhance type safety and make the conditional logic more predictable.

Also applies to: 225-225, 279-279, 295-295, 304-304, 311-311


453-707: Comprehensive refactor of taxonomy handling with excellent WooCommerce integration.

This is a significant improvement that:

  • Adds support for default terms when no terms are posted
  • Implements automatic term creation for missing WooCommerce terms
  • Provides specialized handling for each WooCommerce taxonomy type
  • Maintains proper hierarchical vs non-hierarchical taxonomy handling
  • Integrates with WooCommerce's product attributes system

The logic is well-structured and handles edge cases appropriately.


767-767: LGTM! Consistent strict type comparisons in meta field processing.

The changes maintain the pattern of using strict equality comparisons for better type safety throughout the meta field processing logic.

Also applies to: 851-851, 853-853


906-976: Excellent rewrite of the woo_attribute method.

The rewritten method provides significant improvements:

  • Excludes main WooCommerce taxonomies from additional information display unless explicitly visible
  • Handles both numeric term IDs and text inputs properly
  • Creates missing terms automatically for text inputs
  • Prioritizes form-level labels over WooCommerce defaults
  • Returns detailed attribute metadata with proper formatting

This addresses the core issue mentioned in the PR title about displaying term names instead of IDs.


978-1172: Excellent WooCommerce integration with comprehensive attribute filtering.

The new methods provide robust WooCommerce integration:

  1. init_woocommerce_hooks() - Safely initializes WooCommerce filters only when WooCommerce is active
  2. filter_woocommerce_product_attributes() - Comprehensive filtering that:
    • Removes unwanted taxonomies from product display
    • Ensures proper label prioritization (form-level → WooCommerce → formatted fallback)
    • Converts term IDs to human-readable names
    • Handles special cases for shipping classes and visibility terms
    • Strips HTML tags from values

This directly addresses the PR objective of displaying term names instead of term IDs and provides excellent user experience improvements.

@arifulhoque7

Copy link
Copy Markdown
Contributor Author

Could not built properly @arifulhoque7 vai <img width="2092" height="682" alt="CleanShot 2025-07-30 at 19 05 44@2x" src="https://github.com/user-attachments/assets/f17b5728-2ae6-4a21-b3b3 CleanShot 2025-07-30 at 19 06 41@2x -1f1547a7dd4f" /> CleanShot 2025-07-31 at 10 09 51

done vai check this @Rubaiyat-E-Mohammad

@Rubaiyat-E-Mohammad

Rubaiyat-E-Mohammad commented Aug 1, 2025

Copy link
Copy Markdown
Contributor

Detected issues in the following video! @arifulhoque7 vai

CleanShot.2025-08-01.at.16.04.38.1.mp4

@arifulhoque7

arifulhoque7 commented Aug 3, 2025

Copy link
Copy Markdown
Contributor Author

Detected issues in the following video! @arifulhoque7 vai

CleanShot.2025-08-01.at.16.04.38.1.mp4

please check now it is okay @Rubaiyat-E-Mohammad vai

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🔭 Outside diff range comments (1)
assets/css/admin/form-builder.css (1)

1219-1246: Four identical rule blocks inflate bundle size.

The block that styles
.wpuf-btn-outline.wpuf-btn-primary:hover appears four times (1219-1246, 1231-1247, 1243-1249 etc.). Besides increasing CSS size ~140 bytes per copy, it makes maintenance error-prone.

Consolidate them into a single block:

-/* three duplicated blocks removed for brevity */

.wpuf-btn-outline.wpuf-btn-primary:hover {
  --tw-text-opacity: 1;
  color: var(--fallback-pc,oklch(var(--pc)/var(--tw-text-opacity)));
}

@supports (color: color-mix(in oklab, black, black)) {
  .wpuf-btn-outline.wpuf-btn-primary:hover {
    background-color: color-mix(in oklab,
      var(--fallback-p,oklch(var(--p)/1)) 90%, black);
    border-color: color-mix(in oklab,
      var(--fallback-p,oklch(var(--p)/1)) 90%, black);
  }
}

Removing the redundant copies shaves ~0.5 KB off the file and simplifies future edits.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef6b970 and 3898fc8.

📒 Files selected for processing (4)
  • admin/form-builder/assets/js/form-builder.js (1 hunks)
  • assets/css/admin/form-builder.css (35 hunks)
  • assets/js-templates/form-components.php (1 hunks)
  • assets/js/wpuf-form-builder.js (1 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
assets/css/admin/form-builder.css

[error] 851-851: Duplicate properties can lead to unexpected behavior and may override previous declarations unintentionally.

transition-property is already defined here.

Remove or rename the duplicate property to ensure consistent styling.

(lint/suspicious/noDuplicateProperties)


[error] 1799-1799: Duplicate properties can lead to unexpected behavior and may override previous declarations unintentionally.

transition-property is already defined here.

Remove or rename the duplicate property to ensure consistent styling.

(lint/suspicious/noDuplicateProperties)

🔇 Additional comments (3)
assets/js-templates/form-components.php (1)

1439-1449: LGTM! Improved UX with controlled taxonomy selection.

The change from a text input to a select dropdown for the 'ajax' type taxonomy field is well-implemented. This provides better user experience by offering predefined options instead of free text entry, which aligns with the backend WooCommerce taxonomy handling improvements. The implementation correctly uses Vue.js data binding and maintains consistency with other select elements in the template.

Key benefits:

  • More controlled and predictable user input
  • Better data validation and consistency
  • Improved accessibility with semantic select element
  • Consistent styling with other form selects
admin/form-builder/assets/js/form-builder.js (1)

139-143: LGTM! Simplified field update logic.

The removal of the is_new property check streamlines the field update logic, allowing more consistent updates regardless of field state. This aligns well with the WooCommerce taxonomy enhancements mentioned in the PR.

assets/js/wpuf-form-builder.js (1)

139-143: LGTM! Consistent with admin form builder changes.

This change mirrors the identical modification in the admin form builder, ensuring consistent field update behavior across different contexts. The removal of the is_new property check maintains synchronization between form builder implementations.

Comment thread assets/css/admin/form-builder.css Outdated
Comment thread assets/css/admin/form-builder.css Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🔭 Outside diff range comments (1)
assets/css/admin/form-builder.css (1)

1000-1014: Collapse repeated transition rules in .wpuf-dropdown-content

transition-property and transition-timing-function are each declared three times, creating the same duplicate-property error that breaks the build.

-  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
-  transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
-  visibility: hidden;
-  opacity: 0;
-  transform-origin: top;
-  --tw-scale-x: .95;
-  --tw-scale-y: .95;
-  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate)) skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));
-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-backdrop-filter;
-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;
-  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
-  transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
+  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
+  visibility: hidden;
+  opacity: 0;
+  transform-origin: top;
+  --tw-scale-x: .95;
+  --tw-scale-y: .95;
+  transform: translate(var(--tw-translate-x), var(--tw-translate-y)) rotate(var(--tw-rotate))
+    skewX(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x))
+    scaleY(var(--tw-scale-y));
+  transition-property: color, background-color, border-color, text-decoration-color,
+    fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter,
+    -webkit-backdrop-filter;
♻️ Duplicate comments (2)
assets/css/admin/form-builder.css (2)

850-853: Deduplicate transition-property declarations
Three identical transition-property rules are declared back-to-back. Keep one canonical version to avoid Biome’s noDuplicateProperties error.

-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, -webkit-backdrop-filter;
-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter;
-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;
+  transition-property: color, background-color, border-color, text-decoration-color,
+    fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter,
+    -webkit-backdrop-filter;

1798-1801: Duplicate transition directives in .wpuf-modal-box
transition-property and transition-timing-function are specified twice, triggering the same linter failure flagged earlier. Keep one of each.

-  transition-property: color, background-color, border-color, text-decoration-color, fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter, -webkit-backdrop-filter;
-  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
-  transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
+  transition-property: color, background-color, border-color, text-decoration-color,
+    fill, stroke, opacity, box-shadow, transform, filter, backdrop-filter,
+    -webkit-backdrop-filter;
+  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3898fc8 and 9961f8b.

📒 Files selected for processing (1)
  • assets/css/admin/form-builder.css (34 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
assets/css/admin/form-builder.css

[error] 851-851: Duplicate properties can lead to unexpected behavior and may override previous declarations unintentionally.

transition-property is already defined here.

Remove or rename the duplicate property to ensure consistent styling.

(lint/suspicious/noDuplicateProperties)


[error] 1800-1800: Duplicate properties can lead to unexpected behavior and may override previous declarations unintentionally.

transition-timing-function is already defined here.

Remove or rename the duplicate property to ensure consistent styling.

(lint/suspicious/noDuplicateProperties)

Comment thread assets/css/admin/form-builder.css Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
includes/Traits/FieldableTrait.php (1)

561-1200: Well-designed specialized handlers for WooCommerce taxonomies.

The handler methods are comprehensive and address specific requirements:

  • Product type handler with extensive ID/slug mapping
  • Proper term creation for missing terms
  • Cache clearing for WooCommerce compatibility
  • Extensive logging for debugging

However, there are unused parameters that should be cleaned up:

Apply this diff to remove unused parameters:

-    protected function handle_product_type( $post_id, $taxonomy_name, $posted_terms ) {
+    protected function handle_product_type( $post_id, $posted_terms ) {
         // Log incoming data
         error_log( 'WPUF Product Type - Input: ' . print_r( $posted_terms, true ) );

-    protected function handle_shipping_class( $post_id, $taxonomy_name, $posted_terms ) {
+    protected function handle_shipping_class( $post_id, $posted_terms ) {
         // Clear existing shipping classes
         wp_set_object_terms( $post_id, [], 'product_shipping_class' );

-    protected function handle_product_visibility( $post_id, $taxonomy_name, $posted_terms ) {
+    protected function handle_product_visibility( $post_id, $posted_terms ) {
         error_log( 'WPUF Product Visibility - Input: ' . print_r( $posted_terms, true ) );

And update the method calls accordingly in the main handler method.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9961f8b and d086bde.

📒 Files selected for processing (4)
  • includes/Ajax/Frontend_Form_Ajax.php (2 hunks)
  • includes/Traits/FieldableTrait.php (11 hunks)
  • includes/functions/woocommerce-attribute-labels.php (1 hunks)
  • wpuf-functions.php (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • wpuf-functions.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Ajax/Frontend_Form_Ajax.php
🧰 Additional context used
🪛 GitHub Check: Run PHPCS inspection
includes/functions/woocommerce-attribute-labels.php

[failure] 53-53:
Expected 1 newline at end of file; 0 found


[failure] 51-51:
Whitespace found at end of line


[failure] 47-47:
Whitespace found at end of line


[failure] 39-39:
Whitespace found at end of line


[failure] 34-34:
Whitespace found at end of line


[failure] 26-26:
Whitespace found at end of line


[failure] 18-18:
Whitespace found at end of line

🪛 PHPMD (2.15.0)
includes/Traits/FieldableTrait.php

623-623: Avoid unused parameters such as '$taxonomy_name'. (Unused Code Rules)

(UnusedFormalParameter)


766-766: Avoid unused parameters such as '$taxonomy_name'. (Unused Code Rules)

(UnusedFormalParameter)


981-981: Avoid unused parameters such as '$taxonomy_name'. (Unused Code Rules)

(UnusedFormalParameter)

🔇 Additional comments (5)
includes/functions/woocommerce-attribute-labels.php (1)

30-52: LGTM! Well-structured label customization logic.

The function follows a logical fallback hierarchy:

  1. Custom labels from product meta (highest priority)
  2. Predefined defaults for known WooCommerce taxonomies
  3. Original label (fallback)

The parameter validation and internationalization are properly implemented.

includes/Traits/FieldableTrait.php (4)

119-189: LGTM! Improved type safety and WooCommerce taxonomy handling.

The changes enhance the code in several important ways:

  • Strict type comparisons (===) improve reliability and prevent type coercion issues
  • WooCommerce taxonomy normalization ensures consistent naming (e.g., product_categoryproduct_cat)
  • Adding is_woocommerce flags enables specialized handling downstream
  • Setting hierarchical=true for shipping classes with default select type is appropriate

453-550: Excellent refactor that properly separates WooCommerce from regular taxonomy handling.

This refactor addresses the core PR objectives by:

  • Storing form field labels in post meta for consistent display
  • Delegating WooCommerce taxonomies to specialized handlers
  • Adding comprehensive product data synchronization
  • Including extensive logging for debugging taxonomy assignments
  • Providing fallback logic for missing product types

The separation of concerns makes the code more maintainable and reliable.


1431-1501: Perfect! This directly addresses the PR's core objective.

The changes successfully fix the "Display term names instead of term IDs" issue by:

  • Converting numeric term IDs to human-readable names
  • Creating missing terms automatically for text inputs
  • Prioritizing form field labels for consistent display
  • Properly excluding main taxonomies from additional information display

The logic properly handles both numeric IDs and text values, ensuring reliable term name display.


1503-1644: Comprehensive WooCommerce integration that completes the attribute display fixes.

The hook methods provide:

  • Proper integration with WooCommerce display filters
  • Removal of unwanted taxonomies from additional information
  • Extensive term ID to name conversion with special handling for shipping classes and visibility
  • Form field label prioritization for consistent display
  • Proper handling of edge cases and fallbacks

This ensures that WooCommerce product attributes display correctly with human-readable names instead of IDs.

Comment thread includes/functions/woocommerce-attribute-labels.php Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
includes/Traits/FieldableTrait.php (2)

453-546: Excellent modularization of taxonomy handling!

The refactor significantly improves the code organization by separating WooCommerce and regular taxonomy handling. The addition of taxonomy label storage and comprehensive WooCommerce product data synchronization is well-implemented.

Consider adding error handling for the WooCommerce method calls to make the code more robust against edge cases.


970-1210: Solid implementation of visibility and attribute handling.

The product visibility handling properly maps term IDs to slugs, and the attribute processing correctly converts terms and builds WooCommerce-compatible attribute arrays. The text taxonomy handling with automatic term creation is a nice touch.

Clean up the unused variables flagged by static analysis (lines 1030, 1065) to improve code quality:

-        $result = wp_set_object_terms( $post_id, $terms_to_set, 'product_visibility', false );
+        wp_set_object_terms( $post_id, $terms_to_set, 'product_visibility', false );

-        $saved_terms = wp_get_object_terms( $post_id, 'product_visibility', array( 'fields' => 'slugs' ) );
+        // Terms saved successfully - no need to verify here
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d086bde and f12f7e2.

📒 Files selected for processing (2)
  • includes/Ajax/Frontend_Form_Ajax.php (2 hunks)
  • includes/Traits/FieldableTrait.php (11 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • includes/Ajax/Frontend_Form_Ajax.php
🧰 Additional context used
🪛 PHPMD (2.15.0)
includes/Traits/FieldableTrait.php

521-521: Avoid unused local variables such as '$saved_visibility'. (Unused Code Rules)

(UnusedLocalVariable)


619-619: Avoid unused parameters such as '$taxonomy_name'. (Unused Code Rules)

(UnusedFormalParameter)


678-678: Avoid unused local variables such as '$result'. (Unused Code Rules)

(UnusedLocalVariable)


700-700: Avoid unused local variables such as '$saved_types'. (Unused Code Rules)

(UnusedLocalVariable)


755-755: Avoid unused parameters such as '$taxonomy_name'. (Unused Code Rules)

(UnusedFormalParameter)


970-970: Avoid unused parameters such as '$taxonomy_name'. (Unused Code Rules)

(UnusedFormalParameter)


1030-1030: Avoid unused local variables such as '$result'. (Unused Code Rules)

(UnusedLocalVariable)


1065-1065: Avoid unused local variables such as '$saved_terms'. (Unused Code Rules)

(UnusedLocalVariable)

🔇 Additional comments (5)
includes/Traits/FieldableTrait.php (5)

119-119: Excellent improvements to type safety and WooCommerce integration!

The strict type comparisons (===) improve type safety, and the new WooCommerce taxonomy normalization logic is well-implemented. The normalization of product_category to product_cat and the special handling for shipping class with hierarchical flag and default type are appropriate.

Also applies to: 131-131, 136-136, 159-159, 164-183


222-225: Good improvement to type safety.

The strict comparison operators (===) prevent potential type coercion issues in reCAPTCHA validation, making the code more reliable.

Also applies to: 279-280, 295-296, 304-305, 311-312


781-965: Excellent comprehensive WooCommerce product data synchronization!

The implementation provides thorough synchronization of product data with WooCommerce standards, including product type-specific meta handling, visibility synchronization, and comprehensive meta field initialization. This ensures data consistency and prevents missing meta issues.


1270-1270: Good type safety improvements.

The strict comparisons prevent type coercion issues in the meta field processing logic, particularly for the multiple field check and ACF compatibility handling.

Also applies to: 1354-1356


1409-1622: Excellent refactor of WooCommerce attribute handling with comprehensive integration!

The updated woo_attribute method provides much better term handling with proper ID-to-name conversion, and the new hook methods enable seamless WooCommerce integration. The label prioritization logic (form field → WooCommerce → formatted name) is well-designed.

The filter_woocommerce_product_attributes method comprehensively handles edge cases for different taxonomy types and ensures consistent display.

Note regarding past review comment: While there was a previous suggestion to use the "This taxonomy is a WooCommerce attribute" option from form builder field settings, the current implementation provides more comprehensive and automatic handling that covers edge cases and ensures consistency across different scenarios. The current approach appears more robust.

Comment thread includes/Traits/FieldableTrait.php
…-display-term-labels

# Conflicts:
#	admin/form-builder/assets/js/form-builder.js
#	assets/css/admin/form-builder.css
#	assets/js/wpuf-form-builder.js
#	includes/Traits/FieldableTrait.php
#	wpuf-functions.php
- Sanitize $_POST[ $taxonomy_name ] (array_map sanitize_text_field / sanitize_text_field) after wp_unslash before passing to term functions
- Add strict true to all in_array() calls in the trait (PHPCS zero-tolerance)
@arifulhoque7

Copy link
Copy Markdown
Contributor Author

Review fixes pushed:

  • includes/Traits/FieldableTrait.php$_POST[ $taxonomy_name ] is now sanitized (array_map( 'sanitize_text_field', ... ) for arrays, sanitize_text_field() for scalars) after wp_unslash(), before the values reach wp_set_object_terms/wp_insert_term.
  • Added strict true to all in_array() calls in the trait (PHPCS zero-tolerance).

Two follow-ups (not changed, flagged for QA — changing them risks regressing the new dispatcher):

  1. set_default_taxonomy(): develop called it inside set_custom_taxonomy for the narrow 'posted taxonomy not object-in-taxonomy' fallback. The callers still call it for the no-taxonomy case, but please verify form-configured default taxonomy terms still apply for a post-form that has a taxonomy field but the term isn't object-in-taxonomy.
  2. New public handlers (handle_woocommerce_taxonomy, filter_woocommerce_product_attributes, etc.) could use @since WPUF_SINCE docblocks for consistency.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants