Created
July 28, 2026 08:52
-
-
Save plugin-republic/d1f5c80d6fc0794d87b040f55267a746 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'woocommerce_order_item_display_meta_value', 'my_pewc_hide_field_value_by_type', 20, 3 ); | |
| function my_pewc_hide_field_value_by_type( $display_value, $meta, $order_item ) { | |
| if ( ! is_admin() ) { | |
| return $display_value; | |
| } | |
| // Field types to hide the entered value for (price-only display) | |
| $target_types = array( 'radio-group', 'calculation' ); | |
| $field = my_pewc_find_field_by_meta_key( $meta->key, $order_item ); | |
| if ( ! $field || empty( $field['type'] ) || ! in_array( $field['type'], $target_types, true ) ) { | |
| return $display_value; | |
| } | |
| // Keep only the wc_price() markup, drop the entered value | |
| if ( preg_match( '/<span class="woocommerce-Price-amount[^"]*">.*?<\/span>(<\/bdi>)?/s', $display_value, $matches ) ) { | |
| return $matches[0]; | |
| } | |
| return ''; | |
| } | |
| function my_pewc_find_field_by_meta_key( $meta_key, $order_item ) { | |
| $product_extras = $order_item->get_meta( 'product_extras' ); | |
| if ( empty( $product_extras['groups'] ) ) { | |
| return false; | |
| } | |
| // Strip the leading underscore PEWC adds to the meta key | |
| $target_label = ltrim( $meta_key, '_' ); | |
| $all_groups = pewc_rebuild_cart_item_data( $product_extras, 'order' ); | |
| foreach ( $all_groups as $group ) { | |
| if ( ! $group ) { | |
| continue; | |
| } | |
| foreach ( $group as $field_id => $field ) { | |
| if ( ! is_array( $field ) ) { | |
| continue; | |
| } | |
| $label = ! empty( $field['label'] ) ? $field['label'] : ( $field['id'] ?? '' ); | |
| if ( $label === $target_label ) { | |
| return $field; | |
| } | |
| } | |
| } | |
| return false; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment