WC_Products_Tracking::track_product_category_created()publicWC 1.0

Send a Tracks event when a product category is created.

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

Хуков нет.

Возвращает

null. Ничего.

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

$WC_Products_Tracking = new WC_Products_Tracking();
$WC_Products_Tracking->track_product_category_created( $category_id );
$category_id(int) (обязательный)
Category ID.

Код WC_Products_Tracking::track_product_category_created() WC 6.9.4

public function track_product_category_created( $category_id ) {
	// phpcs:disable WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
	// Only track category creation from the edit product screen or the
	// category management screen (which both occur via AJAX).
	if (
		! Constants::is_defined( 'DOING_AJAX' ) ||
		empty( $_POST['action'] ) ||
		(
			// Product Categories screen.
			'add-tag' !== $_POST['action'] &&
			// Edit Product screen.
			'add-product_cat' !== $_POST['action']
		)
	) {
		return;
	}

	$category        = get_term( $category_id, 'product_cat' );
	$parent_category = $category->parent > 0 ? 'Other' : 'None';
	if ( $category->parent > 0 ) {
		$parent = get_term( $category_id, 'product_cat' );
		if ( 'uncategorized' === $parent->name ) {
			$parent_category = 'Uncategorized';
		}
	}
	$properties = array(
		'category_id'     => $category_id,
		'parent_id'       => $category->parent,
		'parent_category' => $parent_category,
		'page'            => ( 'add-tag' === $_POST['action'] ) ? 'categories' : 'product',
		'display_type'    => isset( $_POST['display_type'] ) ? wp_unslash( $_POST['display_type'] ) : '',
		'image'           => isset( $_POST['product_cat_thumbnail_id'] ) && '' !== $_POST['product_cat_thumbnail_id'] ? 'Yes' : 'No',
	);
	// phpcs:enable

	WC_Tracks::record_event( 'product_category_add', $properties );
}