class-wc-widget-brand-description.php
1 year ago
class-wc-widget-brand-nav.php
7 months ago
class-wc-widget-brand-thumbnails.php
1 year ago
class-wc-widget-cart.php
3 years ago
class-wc-widget-layered-nav-filters.php
2 years ago
class-wc-widget-layered-nav.php
3 months ago
class-wc-widget-price-filter.php
7 months ago
class-wc-widget-product-categories.php
7 months ago
class-wc-widget-product-search.php
5 years ago
class-wc-widget-product-tag-cloud.php
5 years ago
class-wc-widget-products.php
1 year ago
class-wc-widget-rating-filter.php
5 years ago
class-wc-widget-recent-reviews.php
2 months ago
class-wc-widget-recently-viewed.php
1 year ago
class-wc-widget-top-rated-products.php
5 years ago
class-wc-widget-cart.php
83 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Shopping Cart Widget. |
| 4 | * |
| 5 | * Displays shopping cart widget. |
| 6 | * |
| 7 | * @package WooCommerce\Widgets |
| 8 | * @version 2.3.0 |
| 9 | */ |
| 10 | |
| 11 | defined( 'ABSPATH' ) || exit; |
| 12 | |
| 13 | /** |
| 14 | * Widget cart class. |
| 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 customer shopping cart.', 'woocommerce' ); |
| 24 | $this->widget_id = 'woocommerce_widget_cart'; |
| 25 | $this->widget_name = __( '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 | |
| 39 | if ( is_customize_preview() ) { |
| 40 | wp_enqueue_script( 'wc-cart-fragments' ); |
| 41 | } |
| 42 | |
| 43 | parent::__construct(); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Output widget. |
| 48 | * |
| 49 | * @see WP_Widget |
| 50 | * |
| 51 | * @param array $args Arguments. |
| 52 | * @param array $instance Widget instance. |
| 53 | */ |
| 54 | public function widget( $args, $instance ) { |
| 55 | if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | wp_enqueue_script( 'wc-cart-fragments' ); |
| 60 | |
| 61 | $hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1; |
| 62 | |
| 63 | if ( ! isset( $instance['title'] ) ) { |
| 64 | $instance['title'] = __( 'Cart', 'woocommerce' ); |
| 65 | } |
| 66 | |
| 67 | $this->widget_start( $args, $instance ); |
| 68 | |
| 69 | if ( $hide_if_empty ) { |
| 70 | echo '<div class="hide_cart_widget_if_empty">'; |
| 71 | } |
| 72 | |
| 73 | // Insert cart widget placeholder - code in woocommerce.js will update this on page load. |
| 74 | echo '<div class="widget_shopping_cart_content"></div>'; |
| 75 | |
| 76 | if ( $hide_if_empty ) { |
| 77 | echo '</div>'; |
| 78 | } |
| 79 | |
| 80 | $this->widget_end( $args ); |
| 81 | } |
| 82 | } |
| 83 |