WC_Products_Tracking::track_product_updated_client_side()publicWC 1.0

Track the Update button being clicked on the client side. This is needed because track_product_updated (using the edit_post is called in response to a number of other triggers.

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

Хуков нет.

Возвращает

null. Ничего.

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

$WC_Products_Tracking = new WC_Products_Tracking();
$WC_Products_Tracking->track_product_updated_client_side( $post );
$post(WP_Post) (обязательный)
The post, not used.

Код WC_Products_Tracking::track_product_updated_client_side() WC 7.1.0

public function track_product_updated_client_side( $post ) {
	wc_enqueue_js(
		"
		if ( $( 'h1.wp-heading-inline' ).text().trim() === '" . __( 'Edit product', 'woocommerce' ) . "') {
			var initialStockValue = $( '#_stock' ).val();
			var isBlockEditor = false;
			var child_element = '#publish';

			if ( $( '.block-editor' ).length !== 0 && $( '.block-editor' )[0] ) {
    			isBlockEditor = true;
			}

			if ( isBlockEditor ) {
				child_element = '.editor-post-publish-button';
			}

			$( '#wpwrap' ).on( 'click', child_element, function() {
				var description_value  = '';
				var tagsText = '';
				var currentStockValue = $( '#_stock' ).val();

				if ( ! isBlockEditor ) {
					tagsText          = $( '[name=\"tax_input[product_tag]\"]' ).val();
					if ( $( '#content' ).is( ':visible' ) ) {
						description_value = $( '#content' ).val();	
					} else if ( typeof tinymce === 'object' && tinymce.get( 'content' ) ) {
						description_value = tinymce.get( 'content' ).getContent();
					}
				} else {
					description_value  = $( '.block-editor-rich-text__editable' ).text();
				}

				var properties = {
					attributes:				$( '.woocommerce_attribute' ).length,
					categories:				$( '[name=\"tax_input[product_cat][]\"]:checked' ).length,
					cross_sells:			$( '#crosssell_ids option' ).length ? 'Yes' : 'No',
					description:			description_value.trim() !== '' ? 'Yes' : 'No',
					enable_reviews:			$( '#comment_status' ).is( ':checked' ) ? 'Yes' : 'No',
					is_virtual:				$( '#_virtual' ).is( ':checked' ) ? 'Yes' : 'No',
					is_block_editor:		isBlockEditor,
					is_downloadable:		$( '#_downloadable' ).is( ':checked' ) ? 'Yes' : 'No',
					manage_stock:			$( '#_manage_stock' ).is( ':checked' ) ? 'Yes' : 'No',
					menu_order:				$( '#menu_order' ).val() ? 'Yes' : 'No',
					product_gallery:		$( '#product_images_container .product_images > li' ).length,
					product_image:			$( '#_thumbnail_id' ).val() > 0 ? 'Yes' : 'No',
					product_type:			$( '#product-type' ).val(),
					purchase_note:			$( '#_purchase_note' ).val().length ? 'yes' : 'no',
					sale_price:				$( '#_sale_price' ).val() ? 'yes' : 'no',
					short_description:		$( '#excerpt' ).val().length ? 'yes' : 'no',
					stock_quantity_update:	( initialStockValue != currentStockValue ) ? 'Yes' : 'No',
					tags:					tagsText.length > 0 ? tagsText.split( ',' ).length : 0,
					upsells:				$( '#upsell_ids option' ).length ? 'Yes' : 'No',
					weight:					$( '#_weight' ).val() ? 'Yes' : 'No',
				};
				window.wcTracks.recordEvent( 'product_update', properties );
			} );
		}
		"
	);
}