2011-08-10 17:11:11 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Shopping Cart Widget
|
|
|
|
*
|
|
|
|
* Displays shopping cart widget
|
|
|
|
*
|
|
|
|
* @package WooCommerce
|
|
|
|
* @category Widgets
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
class WooCommerce_Widget_Cart extends WP_Widget {
|
|
|
|
|
|
|
|
/** constructor */
|
|
|
|
function WooCommerce_Widget_Cart() {
|
|
|
|
$widget_ops = array( 'description' => __( "Shopping Cart for the sidebar.", 'woothemes') );
|
2011-08-10 17:30:58 +00:00
|
|
|
parent::WP_Widget('shopping_cart', __('WooCommerce Shopping Cart', 'woothemes'), $widget_ops);
|
2011-08-10 17:11:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @see WP_Widget::widget */
|
|
|
|
function widget( $args, $instance ) {
|
|
|
|
|
|
|
|
if (is_cart()) return;
|
|
|
|
|
|
|
|
extract($args);
|
|
|
|
if ( !empty($instance['title']) ) $title = $instance['title']; else $title = __('Cart', 'woothemes');
|
|
|
|
$title = apply_filters('widget_title', $title, $instance, $this->id_base);
|
|
|
|
|
|
|
|
echo $before_widget;
|
|
|
|
if ( $title ) echo $before_title . $title . $after_title;
|
|
|
|
|
|
|
|
echo '<ul class="cart_list">';
|
2011-08-16 14:06:08 +00:00
|
|
|
if (sizeof(woocommerce_cart::$cart_contents)>0) : foreach (woocommerce_cart::$cart_contents as $cart_item_key => $cart_item) :
|
|
|
|
$_product = $cart_item['data'];
|
|
|
|
if ($_product->exists() && $cart_item['quantity']>0) :
|
|
|
|
echo '<li><a href="'.get_permalink($cart_item['product_id']).'">';
|
2011-08-10 17:11:11 +00:00
|
|
|
|
2011-08-16 14:06:08 +00:00
|
|
|
if (has_post_thumbnail($cart_item['product_id'])) echo get_the_post_thumbnail($cart_item['product_id'], 'shop_tiny');
|
2011-08-10 17:11:11 +00:00
|
|
|
else echo '<img src="'.woocommerce::plugin_url(). '/assets/images/placeholder.png" alt="Placeholder" width="'.woocommerce::get_var('shop_tiny_w').'" height="'.woocommerce::get_var('shop_tiny_h').'" />';
|
|
|
|
|
2011-08-16 14:06:08 +00:00
|
|
|
echo apply_filters('woocommerce_cart_widget_product_title', $_product->get_title(), $_product).'</a> '.$cart_item['quantity'].' × '.woocommerce_price($_product->get_price()).'</li>';
|
2011-08-10 17:11:11 +00:00
|
|
|
endif;
|
|
|
|
endforeach;
|
|
|
|
else: echo '<li class="empty">'.__('No products in the cart.', 'woothemes').'</li>'; endif;
|
|
|
|
echo '</ul>';
|
|
|
|
|
|
|
|
if (sizeof(woocommerce_cart::$cart_contents)>0) :
|
|
|
|
echo '<p class="total"><strong>';
|
|
|
|
|
|
|
|
if (get_option('js_prices_include_tax')=='yes') :
|
|
|
|
_e('Total', 'woothemes');
|
|
|
|
else :
|
|
|
|
_e('Subtotal', 'woothemes');
|
|
|
|
endif;
|
|
|
|
|
|
|
|
echo ':</strong> '.woocommerce_cart::get_cart_total();
|
|
|
|
|
|
|
|
echo '</p>';
|
|
|
|
|
|
|
|
do_action( 'woocommerce_widget_shopping_cart_before_buttons' );
|
|
|
|
|
|
|
|
echo '<p class="buttons"><a href="'.woocommerce_cart::get_cart_url().'" class="button">'.__('View Cart →', 'woothemes').'</a> <a href="'.woocommerce_cart::get_checkout_url().'" class="button checkout">'.__('Checkout →', 'woothemes').'</a></p>';
|
|
|
|
endif;
|
|
|
|
echo $after_widget;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @see WP_Widget::update */
|
|
|
|
function update( $new_instance, $old_instance ) {
|
|
|
|
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
|
|
|
|
return $instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @see WP_Widget::form */
|
|
|
|
function form( $instance ) {
|
|
|
|
?>
|
|
|
|
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'woothemes') ?></label>
|
|
|
|
<input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
|
|
|
|
} // class WooCommerce_Widget_Cart
|