Hôm nay tôi sẽ chia sẽ với anh chị cách tùy biến minicart trong woocommerce. Trên mạng có rất nhiều bài hướng dẫn, anh/chị có thể tìm hiểu, ở đây tôi chia sẽ theo cách làm của tôi.
Đầu tiên trên file chứa mã cho việc show mini cart bạn cần gọi biến toàn cục và chống lỗi Warning: Cannot modify header information – headers already sent by (output started at …)
<?php
global $woocommerce;
ob_start();?>
<div class="block_cart clearfix">
<div class="shopping_cart">
<a href="<?php echo WC()->cart->get_cart_url(); ?>" title="Xem giỏ hàng" rel="nofollow"><?php echo sprintf(_n('%d item', '%d sản phẩm', WC()->cart->cart_contents_count, 'woothemes'), WC()->cart->cart_contents_count);?> - <?php echo WC()->cart->get_cart_total(); ?> </a>
<div style="display: none;" class="cart_block block exclusive">
<div class="block_content">
<div class="cart_block_list">
<dl class="products">
<?php if ( sizeof( WC()->cart->get_cart() ) > 0 ) : ?>
<?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) :
$_product = $cart_item['data'];
// Chỉ hiển thị nếu cho phép
if ( ! apply_filters('woocommerce_widget_cart_item_visible', true, $cart_item, $cart_item_key ) || ! $_product->exists() || $cart_item['quantity'] == 0 )continue;
// Lấy price
$product_price = get_option( 'woocommerce_display_cart_prices_excluding_tax' ) == 'yes' || WC()->customer->is_vat_exempt() ? $_product->get_price_excluding_tax() : $_product->get_price();
$product_price = apply_filters( 'woocommerce_cart_item_price_html', woocommerce_price( $product_price ), $cart_item, $cart_item_key );
?>
<dt style="display: block;" class="first_item" data-id="cart_block_product_10_0_0"><a class="cart-images" href="<?php echo get_permalink( $cart_item['product_id'] ); ?>" title="<?php echo apply_filters('woocommerce_widget_cart_product_title', $_product->get_title(), $_product ); ?>">
<?php echo $_product->get_image(); ?>
</a><div class="cart-info"><div class="product-name"><a href="<?php echo get_permalink( $cart_item['product_id'] ); ?>" title="<?php echo apply_filters('woocommerce_widget_cart_product_title', $_product->get_title(), $_product ); ?>" class="cart_block_product_name">
<span class="quantity"><?php printf( '%s × %s', $cart_item['quantity'], $product_price ); ?></span>
<?php echo apply_filters('woocommerce_widget_cart_product_title', $_product->get_title(), $_product ); ?></a></div></div><span class="remove_link">
<?php
echo apply_filters( 'woocommerce_cart_item_remove_link', sprintf( '<a href="%s" title="%s"></a>', esc_url( WC()->cart->get_remove_url( $cart_item_key ) ), __( 'Xóa', 'woocommerce' ) ), $cart_item_key );
?>
</span></dt>
<?php endforeach; ?>
<?php else : ?>
<dt style="display: block;" class="first_item" data-id="cart_block_product_10_0_0"><?php _e('Chưa có sản phẩm trong giỏ hàng', 'woocommerce'); ?></dt>
<?php endif; ?>
</dl><div class="cart-prices"><div class="cart-prices-line last-line"> <span class="price cart_block_total ajax_block_cart_total"><?php echo WC()->cart->get_cart_total(); ?></span> <span style="font-weight:700;">Tổng cộng:</span></div></div>
<?php do_action( 'woocommerce_widget_shopping_cart_before_buttons' ); ?>
<p class="cart-buttons">
<a id="button_order_cart" class="btn btn-default button button-small" href="<?php echo WC()->cart->get_cart_url(); ?>" title="Giỏ hàng" rel="nofollow">Giỏ hàng</a>
<a id="button_order_cart" class="btn btn-default button button-small" href="<?php echo WC()->cart->get_checkout_url(); ?>" title="Thanh toán" rel="nofollow">Thanh toán</a>
</p></div></div></div></div></div>
<?php
ob_end_flush();
ob_end_clean();
?>
|
Nguồn:fcwordpress.net
0 nhận xét: