【发布时间】:2020-01-21 23:19:38
【问题描述】:
我的主导航中有一个 woocommerce 购物车图标。如果购物车中有物品,我希望该图标显示。如果不是,那将被删除。我已经尝试了下面的代码,但它并没有达到我的预期。想法?
if($items_txt = $count_value === 1 ){
$html .= '<span class="xoo-wsc-sc-count">1</span>';}
elseif($items_txt = $count_value === 0 ){
$html .= '';}
这里是完整的原始代码sn-p。
<?php
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
$sy_options = get_option('xoo-wsc-sy-options');//Style options
$options = get_option('xoo-wsc-gl-options');
$count_type = isset( $options['bk-count-type']) ? $options['bk-count-type'] : 'qty_count'; //Count Type
$cart_items_total = wc_price(WC()->cart->subtotal);
$bk_cubi = isset( $sy_options['bk-cubi']) ? $sy_options['bk-cubi'] : ''; // Custom basket icon
if( !$bk_cubi ){
$bk_bit = isset( $sy_options['bk-bit']) ? $sy_options['bk-bit'] : 'xoo-wsc-icon-basket1'; // Basket Icon Type
}
$html = '<a class="xoo-wsc-sc-cont">';
if( $bk_cubi ){
$html .= '<img src="'.$bk_cubi.'" class="xoo-wsc-sc-icon">';
}
else{
$html .= '<span class="xoo-wsc-sc-icon '.$bk_bit.'"></span>';
}
if($count_type == 'qty_count'){
$count_value = WC()->cart->get_cart_contents_count();
}
elseif($count_type == 'item_count'){
$count_value = count(WC()->cart->get_cart());
}
$items_txt = $count_value === 1 ? __('item','side-cart-woocommerce') : __('items','side-cart-woocommerce');
$html .= '<span class="xoo-wsc-sc-count">'.'</span>';
//$html .= '<span class="xoo-wsc-sc-count">'.$count_value.'</span>';
//$html .= '<span class="xoo-wsc-sc-total">'.$cart_items_total.'</span>';
$html .= '</a>';
echo $html;
【问题讨论】:
标签: php woocommerce shopping-cart