WC_Products_Tracking::track_product_category_created()
Send a Tracks event when a product category is created.
Method of the class: WC_Products_Tracking{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WC_Products_Tracking = new WC_Products_Tracking(); $WC_Products_Tracking->track_product_category_created( $category_id );
- $category_id(int) (required)
- Category ID.
WC_Products_Tracking::track_product_category_created() WC Products Tracking::track product category created code WC 9.2.3
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 ); }