WC_Brands_Admin::add_thumbnail_field()publicWC 1.0

Category thumbnails.

Метод класса: WC_Brands_Admin{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WC_Brands_Admin = new WC_Brands_Admin();
$WC_Brands_Admin->add_thumbnail_field();

Код WC_Brands_Admin::add_thumbnail_field() WC 9.4.2

<?php
public function add_thumbnail_field() {
	global $woocommerce;
	?>
	<div class="form-field">
		<label><?php esc_html_e( 'Thumbnail', 'woocommerce' ); ?></label>
		<div id="product_cat_thumbnail" style="float:left;margin-right:10px;"><img src="<?php echo esc_url( wc_placeholder_img_src() ); ?>" width="60px" height="60px" /></div>
		<div style="line-height:60px;">
			<input type="hidden" id="product_cat_thumbnail_id" name="product_cat_thumbnail_id" />
			<button type="button" class="upload_image_button button"><?php esc_html_e( 'Upload/Add image', 'woocommerce' ); ?></button>
			<button type="button" class="remove_image_button button"><?php esc_html_e( 'Remove image', 'woocommerce' ); ?></button>
		</div>
		<script type="text/javascript">

			jQuery(function(){
				// Only show the "remove image" button when needed
				if ( ! jQuery('#product_cat_thumbnail_id').val() ) {
					jQuery('.remove_image_button').hide();
				}

				// Uploading files
				var file_frame;

				jQuery(document).on( 'click', '.upload_image_button', function( event ){

					event.preventDefault();

					// If the media frame already exists, reopen it.
					if ( file_frame ) {
						file_frame.open();
						return;
					}

					// Create the media frame.
					file_frame = wp.media.frames.downloadable_file = wp.media({
						title: '<?php echo esc_js( __( 'Choose an image', 'woocommerce' ) ); ?>',
						button: {
							text: '<?php echo esc_js( __( 'Use image', 'woocommerce' ) ); ?>',
						},
						multiple: false
					});

					// When an image is selected, run a callback.
					file_frame.on( 'select', function() {
						attachment = file_frame.state().get('selection').first().toJSON();

						jQuery('#product_cat_thumbnail_id').val( attachment.id );
						jQuery('#product_cat_thumbnail img').attr('src', attachment.url );
						jQuery('.remove_image_button').show();
					});

					// Finally, open the modal.
					file_frame.open();
				});

				jQuery(document).on( 'click', '.remove_image_button', function( event ){
					jQuery('#product_cat_thumbnail img').attr('src', '<?php echo esc_js( wc_placeholder_img_src() ); ?>');
					jQuery('#product_cat_thumbnail_id').val('');
					jQuery('.remove_image_button').hide();
					return false;
				});
			});

		</script>
		<div class="clear"></div>
	</div>
	<?php
}