1 <?php
 2 /**
 3  * Shopping Cart Widget
 4  *
 5  * Displays shopping cart widget
 6  *
 7  * @author      WooThemes
 8  * @category    Widgets
 9  * @package     WooCommerce/Widgets
10  * @version     2.0.1
11  * @extends     WC_Widget
12  */
13 
14 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
15 
16 class WC_Widget_Cart extends WC_Widget {
17 
18     /**
19      * Constructor
20      */
21     public function __construct() {
22         $this->widget_cssclass    = 'woocommerce widget_shopping_cart';
23         $this->widget_description = __( "Display the user's Cart in the sidebar.", 'woocommerce' );
24         $this->widget_id          = 'woocommerce_widget_cart';
25         $this->widget_name        = __( 'WooCommerce Cart', 'woocommerce' );
26         $this->settings           = array(
27             'title'  => array(
28                 'type'  => 'text',
29                 'std'   => __( 'Cart', 'woocommerce' ),
30                 'label' => __( 'Title', 'woocommerce' )
31             ),
32             'hide_if_empty' => array(
33                 'type'  => 'checkbox',
34                 'std'   => 0,
35                 'label' => __( 'Hide if cart is empty', 'woocommerce' )
36             )
37         );
38         parent::__construct();
39     }
40 
41     /**
42      * widget function.
43      *
44      * @see WP_Widget
45      * @access public
46      * @param array $args
47      * @param array $instance
48      * @return void
49      */
50     public function widget( $args, $instance ) {
51 
52         extract( $args );
53 
54         if ( is_cart() || is_checkout() ) return;
55 
56         $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Cart', 'woocommerce' ) : $instance['title'], $instance, $this->id_base );
57         $hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;
58 
59         echo $before_widget;
60 
61         if ( $title )
62             echo $before_title . $title . $after_title;
63 
64         if ( $hide_if_empty )
65             echo '<div class="hide_cart_widget_if_empty">';
66 
67         // Insert cart widget placeholder - code in woocommerce.js will update this on page load
68         echo '<div class="widget_shopping_cart_content"></div>';
69 
70         if ( $hide_if_empty )
71             echo '</div>';
72 
73         echo $after_widget;
74     }
75 }
76 
77 register_widget( 'WC_Widget_Cart' );
WooCommerce API documentation generated by ApiGen 2.8.0