こんにちは、woocommerce の一番上のカートを取得して、数量と価格を自動的に更新しようとしています。
これをテンプレートとして使用することで、ある程度機能するようになりました。
http://www.amberweinberg.com/developing-custom-woocommerce-themes/
問題は、ajax を使用して 1 つだけでなく 2 つの要素を変更する必要があることです。
ここに私がテーマfuctions.phpファイルで使用しているhtmlがあります
<div class="cartWrapper">
<a href="#" title="Checkout">
<div id="cartsummary"><p>
<span class="cart-bubble cart-contents"><a class="cart-bubble cart-contents"><?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a>
<?php if($woocommerce->cart->get_cart_url() != ''){ $cart=$woocommerce->cart->get_cart_url();}
else {$cart = home_url().'/cart/';};
?></span>
</div>
</a>
<div id="carttotal">
<div id="cartprice">
<p>
<a class="cart-total"><?php echo $woocommerce->cart->get_cart_total() ?></a>
</p>
</div>
<a class="button" href="#" title="Checkout" type="button">View Basket</a>
</div>
</div>
更新せずにカートを自動更新するコード:
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter('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-bubble cart-contents"><?php echo sprintf(_n('%d', '%d', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?></a>
<a class="cart-total"><?php echo $woocommerce->cart->get_cart_total() ?></a>
<?php
$fragments['a.cart-contents a.cart-total'] = ob_get_clean();
return $fragments;
}
問題は、これが機能する一方で、関連する要素で css スタイル oveflow:hidden を使用して非表示にする必要があるカートの合計とアイテムの長いリストが生成されることです。おそらくこれは、ajax要素を間違ってコーディングしたためです。誰かが私を正しい方向に向けることができますか?
ありがとう