Home / Widgets / Product Count Javascript
Duplicate Snippet

Embed Snippet on Your Site

Product Count Javascript

Adds javascript for [product_count] shortcode

<10
Code Preview
js
// Update values in post counter 
	if ( 
		jQuery( '.cwf-products-count' ) 
		&& jQuery( '.cwf-products-count' ).length 
	) {
		// TODO maybe found more suitable event in imagesLoaded?
		$us.$canvas.on( 'resize', function(){
			// Make sure HTML was appended
			setTimeout(() => {
				jQuery( '.cwf-products-count' ).each(function(){
					console.log( 'updating' );
					const $data = jQuery( '.pagination-total-items' );
					const total = $data ? $data.data( 'count' ) : null;
					const first = $data ? $data.data( 'first' ) : false;
					if ( total ) {
						jQuery( this ).find( '.count-total' ).html( total );
					}
					
					if ( first ) {
						jQuery( this ).find( '.count-from-to' ).html( '1-12' );
					}
				});
			}, 10);
		});
	}

Comments

Add a Comment