Automattic\WooCommerce\Internal\Admin

CustomerEffortScoreTracks::get_script_track_edit_php()privateWC 1.0

Returns a generated script for tracking tags added on edit-tags.php page. CES survey is triggered via direct access to wc/customer-effort-score store via wp.data.dispatch method.

Due to lack of options to directly hook ourselves into the ajax post request initiated by edit-tags.php page, we infer a successful request by observing an increase of the number of rows in tags table

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

Хуков нет.

Возвращает

Строку. Generated JavaScript to append to page.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_script_track_edit_php( $action, $title, $first_question, $second_question );
$action(строка) (обязательный)
Action name for the survey.
$title(строка) (обязательный)
Title for the snackbar.
$first_question(строка) (обязательный)
The text for the first question.
$second_question(строка) (обязательный)
The text for the second question.

Код CustomerEffortScoreTracks::get_script_track_edit_php() WC 7.3.0

private function get_script_track_edit_php( $action, $title, $first_question, $second_question ) {
	return sprintf(
		"(function( $ ) {
			'use strict';
			// Hook on submit button and sets a 500ms interval function
			// to determine successful add tag or otherwise.
			$('#addtag #submit').on( 'click', function() {
				const initialCount = $('.tags tbody > tr').length;
				const interval = setInterval( function() {
					if ( $('.tags tbody > tr').length > initialCount ) {
						// New tag detected.
						clearInterval( interval );
						wp.data.dispatch('wc/customer-effort-score').addCesSurvey({ action: '%s', title: '%s', firstQuestion: '%s', secondQuestion: '%s', onsubmitLabel: '%s' });
					} else {
						// Form is no longer loading, most likely failed.
						if ( $( '#addtag .submit .spinner.is-active' ).length < 1 ) {
							clearInterval( interval );
						}
					}
				}, 500 );
			});
		})( jQuery );",
		esc_js( $action ),
		esc_js( $title ),
		esc_js( $first_question ),
		esc_js( $second_question ),
		esc_js( $this->onsubmit_label )
	);
}