我正在尝试更新多个div,但是无法正常工作。
这按预期工作。
add_filter( 'woocommerce_add_to_cart_fragments', 'update_basket' );
function update_basket( $fragments ) {
global $woocommerce;
ob_start();
?>
<span class="bas" style=""><?php echo WC()->cart->get_cart_total(); ?></span>
<?php
$fragments['.bas'] = ob_get_clean();
return $fragments;
}
当我添加第二个div类时,输出根本不会得到更新。
add_filter( 'woocommerce_add_to_cart_fragments', 'update_basket' );
function update_basket( $fragments ) {
global $woocommerce;
ob_start();
?>
<span class="bas" style=""><?php echo WC()->cart->get_cart_total(); ?></span>
<?php $fragments['.bas'] = ob_get_clean(); ?>
<?php ob_start(); ?>
<div class="search-form"> Your Basket:<br/>
<a style="" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"> <?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
</div>
<?php
$fragments['.search-form'] = ob_get_clean();
return $fragments;
}