Woocommerce Product Meta – Strip dd and dt labels
-
I’m trying to output the values of product meta and have it working, but they are wrapped in dd and dt tags and include the label. I would want to strip these to ideally, just leave the value.
Current output:
<dl class="variation"> <dt class="variation-WebsiteDomain">Website Domain:</dt> <dd class="variation-WebsiteDomain"> <p> <a rel="nofollow" href="https://mytest.com">https://mytest.com</a> </p> </dd> </dl>
I would just like the value on it’s own, namely ‘https://mytest.com’.
Anyone had an experience with this before? The code I’m using to generate and display the variation data is:
$_product = apply_filters( 'woocommerce_subscriptions_order_item_product', $subscription->get_product_from_item( $item ), $item ); $item_meta = wcs_get_order_item_meta( $item, $_product ); if ( apply_filters( 'woocommerce_order_item_visible', true, $item ) ) { $item_meta->display(); }
I traced the function in Woo, in
woocommerce/includes/class-wc-order-item-meta.php
and this is the bit I need to edit:
/** * Display meta in a formatted list. * * @param bool $flat (default: false) * @param bool $return (default: false) * @param string $hideprefix (default: _) * @param string $delimiter Delimiter used to separate items when $flat is true * @return string|void */ public function display( $flat = false, $return = false, $hideprefix = '_', $delimiter = ", \n" ) { $output = ''; $formatted_meta = $this->get_formatted( $hideprefix ); if ( ! empty( $formatted_meta ) ) { $meta_list = array(); foreach ( $formatted_meta as $meta ) { if ( $flat ) { $meta_list[] = wp_kses_post( $meta['label'] . ': ' . $meta['value'] ); } else { $meta_list[] = ' <dt class="variation-' . sanitize_html_class( sanitize_text_field( $meta['key'] ) ) . '">' . wp_kses_post( $meta['label'] ) . ':</dt> <dd class="variation-' . sanitize_html_class( sanitize_text_field( $meta['key'] ) ) . '">' . wp_kses_post( wpautop( make_clickable( $meta['value'] ) ) ) . '</dd> '; } } if ( ! empty( $meta_list ) ) { if ( $flat ) { $output .= implode( $delimiter, $meta_list ); } else { $output .= '<dl class="variation">' . implode( '', $meta_list ) . '</dl>'; } } } $output = apply_filters( 'woocommerce_order_items_meta_display', $output, $this ); if ( $return ) { return $output; } else { echo $output; } }
Any way to override this function?
- The topic ‘Woocommerce Product Meta – Strip dd and dt labels’ is closed to new replies.