将html添加到woocommerce产品标题中

问题描述 投票:0回答:1

我希望能够在产品标题中添加一个“ li”标签。为了以一种用户友好的方式实现这一目标,我编写了一个代码,将字符“-”更改为“ li”标签。 但是目前html对“ order-details-table”(例如,当您完成订购时出现)没有影响。是否有另一个过滤器来添加html全局变量,以便每次出现标题时将其从“-”更改为“ li”?-> 我更新了代码,现在html随处可见,仅剩下以下问题:

但是在后端中添加了html,但是将其显示为纯文本,因此它没有任何作用。还有解决这个问题的方法吗?

What the product title looks like at the moment --> the html gets interpreted as normal text

add_filter( 'the_title', 'custom_the_title', 10, 2 );
add_filter( 'woocommerce_cart_item_name', 'custom_the_title', 20, 3);
add_filter( 'woocommerce_order_item_name', 'custom_the_title' );

function custom_the_title( $title){

        $title = str_replace( '-', '<li>', $title );
        $title = str_replace( '.', '</li>', $title );

    return $title;
}

非常感谢您的帮助,并感谢奥地利的问候!塞缪尔

wordpress woocommerce
1个回答
0
投票

您是否正在尝试获得类似的东西?如果没有,请提供更多信息,您希望看到什么?有视觉上的例子吗?您想在哪里查看这些更改?

add_filter( 'the_title', 'custom_the_title', 10, 2 );
add_filter( 'woocommerce_cart_item_name', 'custom_the_title', 20, 3);

function custom_the_title( $title){

        $title = '<li>'.$title.'</li>';
    return $title;
}
© www.soinside.com 2019 - 2024. All rights reserved.