请帮助我,我想在我的 WordPress 网站上显示带有自定义文本和图标的 woocommerce 购物车。我使用此源代码作为参考:https ://docs.woocommerce.com/document/show-cart-contents-total/
我在前端显示它,它看起来像上面链接中的源代码,但我想用里面的图标显示它,我还想更改文本,将其更改为“产品”而不是'项目'
这是我尝试显示该图标和更改后的文本的代码,请帮助我:
<a class="cart-customlocation" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>">
<?php echo sprintf ( _n( '<i class="fa fa-cart"></i>Cart %d product', '<i class="fa fa-cart"></i>Cart %d products s', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
function.php 中的代码:
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment'
);
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-customlocation" href="<?php echo esc_url(wc_get_cart_url()); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>
<?php
$fragments['a.cart-customlocation'] = ob_get_clean();
return $fragments; }
摇曳的蔷薇