Merge pull request #22541 from woocommerce/pr/20830

Init cart widget when added to sidebar via the customizer
This commit is contained in:
Mike Jolley 2019-02-05 10:39:29 +00:00 committed by GitHub
commit 5f5272ba2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -165,4 +165,18 @@ jQuery( function( $ ) {
$( document.body ).on( 'adding_to_cart', function() {
$( '.hide_cart_widget_if_empty' ).closest( '.widget_shopping_cart' ).show();
});
// Customiser support.
var hasSelectiveRefresh = (
'undefined' !== typeof wp &&
wp.customize &&
wp.customize.selectiveRefresh &&
wp.customize.widgetsPreview &&
wp.customize.widgetsPreview.WidgetPartial
);
if ( hasSelectiveRefresh ) {
wp.customize.selectiveRefresh.bind( 'partial-content-rendered', function() {
refresh_cart_fragment();
} );
}
});

View File

@ -36,6 +36,10 @@ class WC_Widget_Cart extends WC_Widget {
),
);
if ( is_customize_preview() ) {
wp_enqueue_script( 'wc-cart-fragments' );
}
parent::__construct();
}
@ -54,6 +58,10 @@ class WC_Widget_Cart extends WC_Widget {
$hide_if_empty = empty( $instance['hide_if_empty'] ) ? 0 : 1;
if ( empty( $instance['title'] ) ) {
$instance['title'] = __( 'Cart', 'woocommerce' );
}
$this->widget_start( $args, $instance );
if ( $hide_if_empty ) {