Skip to content

Instantly share code, notes, and snippets.

@stephanieland352
Created October 24, 2018 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephanieland352/bf3d5d792c64fd97d8d4841173f5410d to your computer and use it in GitHub Desktop.
Save stephanieland352/bf3d5d792c64fd97d8d4841173f5410d to your computer and use it in GitHub Desktop.
A cart link with drop down of woocommrce cart data
<div class="cart-wrap">
<?php global $woocommerce; ?>
<div class="cart_icon" href="<?php echo $woocommerce->cart->get_cart_url(); ?>">
<i class="fa fa-shopping-cart"></i>
</div>
<div class="cart-box">
<h3>Cart Contents :</h3>
<table>
<?php foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$product_id = apply_filters( 'woocommerce_cart_item_product_id', $cart_item['product_id'], $cart_item, $cart_item_key ); ?>
<tr>
<td>
<?php
$thumbnail = apply_filters( 'woocommerce_cart_item_thumbnail', $_product->get_image(), $cart_item, $cart_item_key );
if ( ! $_product->is_visible() )
echo $thumbnail;
else
printf( '<a href="%s">%s</a>', $_product->get_permalink(), $thumbnail );
?>
</td>
<td>
<?php
if ( ! $_product->is_visible() )
echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key );
else
echo apply_filters( 'woocommerce_cart_item_name', sprintf( '<a href="%s">%s</a>', $_product->get_permalink(), $_product->get_title() ), $cart_item, $cart_item_key );
// Meta data
echo WC()->cart->get_item_data( $cart_item );
// Backorder notification
if ( $_product->backorders_require_notification() && $_product->is_on_backorder( $cart_item['quantity'] ) )
echo '<p class="backorder_notification">' . __( 'Available on backorder', 'woocommerce' ) . '</p>';
?>
</td>
<td>
<?php
echo apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $_product ), $cart_item, $cart_item_key );
?>
</td>
</tr>
<?php } ?>
</table>
<p><strong>Total:</strong> <?php echo $woocommerce->cart->get_cart_total(); ?></p>
<a class="cart_view" href="<?php echo $woocommerce->cart->get_cart_url(); ?>">View Cart</a>
<?php if ( is_user_logged_in() ) { ?>
<a class="myaccount" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('My Account','woothemes'); ?>"><?php _e('My Account','woothemes'); ?></a>
<?php }
else { ?>
<a class="myaccount" href="<?php echo get_permalink( get_option('woocommerce_myaccount_page_id') ); ?>" title="<?php _e('Login / Register','woothemes'); ?>"><?php _e('Login / Register','woothemes'); ?></a>
<?php } ?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment