woocommerce/widgets/widget-cart.php

84 lines
3.0 KiB
PHP
Raw Normal View History

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 {
2011-08-26 21:28:55 +00:00
/** Variables to setup the widget. */
var $woo_widget_cssclass;
var $woo_widget_description;
var $woo_widget_idbase;
var $woo_widget_name;
2011-08-10 17:11:11 +00:00
/** constructor */
function WooCommerce_Widget_Cart() {
2011-08-26 21:28:55 +00:00
/* Widget variable settings. */
2012-06-29 21:14:40 +00:00
$this->woo_widget_cssclass = 'widget_shopping_cart';
$this->woo_widget_description = __( "Display the user's Cart in the sidebar.", 'woocommerce' );
$this->woo_widget_idbase = 'woocommerce_widget_cart';
$this->woo_widget_name = __( 'WooCommerce Cart', 'woocommerce' );
2011-08-26 21:28:55 +00:00
/* Widget settings. */
$widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
2011-08-26 21:28:55 +00:00
/* Create the widget. */
$this->WP_Widget( 'shopping_cart', $this->woo_widget_name, $widget_ops );
2011-08-10 17:11:11 +00:00
}
/** @see WP_Widget */
2011-08-10 17:11:11 +00:00
function widget( $args, $instance ) {
global $woocommerce;
extract( $args );
if ( is_cart() || is_checkout() ) return;
$title = apply_filters('widget_title', empty( $instance['title'] ) ? __('Cart', 'woocommerce') : $instance['title'], $instance, $this->id_base );
$hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;
2011-08-10 17:11:11 +00:00
echo $before_widget;
if ( $title )
echo $before_title . $title . $after_title;
$woocommerce->mfunc_wrapper( 'woocommerce_mini_cart()', 'woocommerce_mini_cart', array( $hide_if_empty ? 'hide_cart_widget_if_empty' : '' ) );
2011-08-10 17:11:11 +00:00
echo $after_widget;
if ( $hide_if_empty && sizeof( $woocommerce->cart->get_cart() ) == 0 ) {
$woocommerce->add_inline_js( "
jQuery('.hide_cart_widget_if_empty').closest('.widget').hide();
jQuery('body').bind('adding_to_cart', function(){
jQuery(this).find('.hide_cart_widget_if_empty').closest('.widget').fadeIn();
});
" );
}
2011-08-10 17:11:11 +00:00
}
/** @see WP_Widget->update */
2011-08-10 17:11:11 +00:00
function update( $new_instance, $old_instance ) {
$instance['title'] = strip_tags( stripslashes( $new_instance['title'] ) );
$instance['hide_if_empty'] = empty( $new_instance['hide_if_empty'] ) ? 0 : 1;
2011-08-10 17:11:11 +00:00
return $instance;
}
/** @see WP_Widget->form */
2011-08-10 17:11:11 +00:00
function form( $instance ) {
$hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;
2011-12-19 00:45:24 +00:00
?>
2012-01-05 11:31:22 +00:00
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:', 'woocommerce') ?></label>
2011-12-19 00:45:24 +00:00
<input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" value="<?php if (isset ( $instance['title'])) {echo esc_attr( $instance['title'] );} ?>" /></p>
2011-12-19 00:45:24 +00:00
<p><input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id('hide_if_empty') ); ?>" name="<?php echo esc_attr( $this->get_field_name('hide_if_empty') ); ?>"<?php checked( $hide_if_empty ); ?> />
2012-01-05 11:31:22 +00:00
<label for="<?php echo $this->get_field_id('hide_if_empty'); ?>"><?php _e( 'Hide if cart is empty', 'woocommerce' ); ?></label></p>
2011-12-19 00:45:24 +00:00
<?php
2011-08-10 17:11:11 +00:00
}
} // class WooCommerce_Widget_Cart