class-wc-widget-cart.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. defined( 'ABSPATH' ) || exit;
  11. /**
  12. * Widget cart class.
  13. */
  14. class WC_Widget_Cart extends WC_Widget {
  15. /**
  16. * Constructor.
  17. */
  18. public function __construct() {
  19. $this->widget_cssclass = 'woocommerce widget_shopping_cart';
  20. $this->widget_description = __( 'Display the customer shopping cart.', 'woocommerce' );
  21. $this->widget_id = 'woocommerce_widget_cart';
  22. $this->widget_name = __( 'Cart', 'woocommerce' );
  23. $this->settings = array(
  24. 'title' => array(
  25. 'type' => 'text',
  26. 'std' => __( 'Cart', 'woocommerce' ),
  27. 'label' => __( 'Title', 'woocommerce' ),
  28. ),
  29. 'hide_if_empty' => array(
  30. 'type' => 'checkbox',
  31. 'std' => 0,
  32. 'label' => __( 'Hide if cart is empty', 'woocommerce' ),
  33. ),
  34. );
  35. parent::__construct();
  36. }
  37. /**
  38. * Output widget.
  39. *
  40. * @see WP_Widget
  41. *
  42. * @param array $args Arguments.
  43. * @param array $instance Widget instance.
  44. */
  45. public function widget( $args, $instance ) {
  46. if ( apply_filters( 'woocommerce_widget_cart_is_hidden', is_cart() || is_checkout() ) ) {
  47. return;
  48. }
  49. $hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;
  50. $this->widget_start( $args, $instance );
  51. if ( $hide_if_empty ) {
  52. echo '<div class="hide_cart_widget_if_empty">';
  53. }
  54. // Insert cart widget placeholder - code in woocommerce.js will update this on page load.
  55. echo '<div class="widget_shopping_cart_content"></div>';
  56. if ( $hide_if_empty ) {
  57. echo '</div>';
  58. }
  59. $this->widget_end( $args );
  60. }
  61. }