我試圖在空的時候隱藏我的購物車,因此我決定在購物車爲空時添加CSS類到購物車HTML項目,這裏是我的當前代碼:當Woocommerce購物車爲空時,爲商品添加CSS類
function x_woocommerce_navbar_menu_item($items, $args) {
if (WC()->cart->cart_contents_count == 0) {
echo '<script type="text/javascript">
$(document).ready(function() {
$("#header_cart").addClass("zero");
});
</script>';
}
我加入這個我functionts.php文件
我錯過了什麼?
add_action('wp_footer','x_woocommerce_navbar_menu_item');如果你正在添加腳本 –