2 回答
TA贡献1895条经验 获得超3个赞
这很丑陋,但它应该可以解决问题:
$span = groovy_menu_woocommerce_mini_cart_counter($qty);
$spanWithId = "<span id='the-id'" . substr($span, 5, strlen($span));
$output_html .= $spanWithId;
echo "$spanWithId";
输出:
<span id='the-id' class="gm-cart-counter">2</span>
尝试这个
global $woocommerce;
$qty = 0;
if ($tks == true) {
$qty = $woocommerce->cart->get_cart_contents_count();
}
$cartIcon = 'fa fa-shopping-cart';
$span = groovy_menu_woocommerce_mini_cart_counter($qty);
$spanWithId = "<span id='the-id'" . substr($span, 5, strlen($span));
$output_html .= '
<div class="gm-minicart minicartmarie">
<a href="' . get_permalink( wc_get_page_id( 'cart' ) ) . '" class="gm-minicart-link minicartmarie">
<div class="gm-badge">
<i class="gm-icon ' . esc_attr( $cartIcon ) . '"></i>
' . $spanWithId . '
</div>
</a>
</div>
';
您正确地替换了对的调用,groovy_menu_woocommerce_mini_cart_counter($qty)但;在中断它的语句中包含了 a 。
此外,而不是echoing$spanWithId你应该echo $output_html
TA贡献1860条经验 获得超9个赞
这就是我要做的。
// create a wrapper function that injects the id
function menu_with_id($qty, $id){
$span = groovy_menu_woocommerce_mini_cart_counter($qty);
return str_replace('<span', "<span id='$id'", $span);
}
// then replace it
$output_html .= ' ' . menu_with_id($qty, $id) . ' ';
- 2 回答
- 0 关注
- 140 浏览
添加回答
举报