yoondolmon
yoondolmon

Reputation: 55

can I add id or class 'wc_display_item_meta'

in woocommerce checkout result page, 'wc-item-meta' list

I want add id or class in 'strong' and 'p' element, to control with css. (change text to image)

like p class="01_S", strong class="wc-item-meta-label 01_S"

is there any solution?

<ul class="wc-item-meta">
    <li>
        <strong class="wc-item-meta-label">sleeve :</strong>
        <p>01_S</p>
    </li>
    <li>
        <strong class="wc-item-meta-label">hood :</strong>
        <p>02_M</p>
    </li>
</ul>

Upvotes: 0

Views: 1273

Answers (1)

itzmekhokan
itzmekhokan

Reputation: 2770

Use the follows code snippet in your active theme's functions.php to achieve the above -

function modify_woocommerce_display_item_meta( $html, $item, $args ) {
    $strings = array();
    $html = '';
    foreach ( $item->get_formatted_meta_data() as $meta_id => $meta ) {
        // remove strip tags
        $display_value = wp_strip_all_tags( $meta->display_value );
        $value     = $args['autop'] ? wp_kses_post( $display_value ) : wp_kses_post( make_clickable( trim( $display_value ) ) );
        $args['label_before'] = '<strong class="wc-item-meta-label ' . wp_strip_all_tags( $display_value ) . '">';
        $args['label_after'] = ':</strong> ';
        $strings[] = $args['label_before'] . wp_kses_post( $meta->display_key ) . $args['label_after'] . '<p class="' . wp_strip_all_tags( $display_value ) . '">' . $value . '</p>';
    }

    if ( $strings ) {
        $html = $args['before'] . implode( $args['separator'], $strings ) . $args['after'];
    }
    return $html;

}
add_filter( 'woocommerce_display_item_meta', 'modify_woocommerce_display_item_meta', 99, 3 );

Upvotes: 2

Related Questions