Add product meta data to published product tracks (#31355)

This commit is contained in:
Joshua T Flowers 2022-01-21 17:19:56 -05:00 committed by GitHub
parent dc381f4305
commit b5ae232106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 8 deletions

View File

@ -20,7 +20,7 @@ class WC_Products_Tracking {
add_action( 'load-edit.php', array( $this, 'track_products_view' ), 10 );
add_action( 'load-edit-tags.php', array( $this, 'track_categories_and_tags_view' ), 10, 2 );
add_action( 'edit_post', array( $this, 'track_product_updated' ), 10, 2 );
add_action( 'transition_post_status', array( $this, 'track_product_published' ), 10, 3 );
add_action( 'wp_after_insert_post', array( $this, 'track_product_published' ), 10, 4 );
add_action( 'created_product_cat', array( $this, 'track_product_category_created' ) );
add_action( 'add_meta_boxes_product', array( $this, 'track_product_updated_client_side' ), 10 );
}
@ -156,21 +156,29 @@ class WC_Products_Tracking {
/**
* Send a Tracks event when a product is published.
*
* @param string $new_status New post_status.
* @param string $old_status Previous post_status.
* @param object $post WordPress post.
* @param int $post_id Post ID.
* @param WP_Post $post Post object.
* @param bool $update Whether this is an existing post being updated.
* @param null|WP_Post $post_before Null for new posts, the WP_Post object prior
* to the update for updated posts.
*/
public function track_product_published( $new_status, $old_status, $post ) {
public function track_product_published( $post_id, $post, $update, $post_before ) {
if (
'product' !== $post->post_type ||
'publish' !== $new_status ||
'publish' === $old_status
'publish' !== $post->post_status ||
( $post_before && 'publish' === $post_before->post_status )
) {
return;
}
$product = wc_get_product( $post_id );
$properties = array(
'product_id' => $post->ID,
'product_id' => $post_id,
'product_type' => $product->get_type(),
'is_downloadable' => $product->is_downloadable() ? 'yes' : 'no',
'is_virtual' => $product->is_virtual() ? 'yes' : 'no',
'manage_stock' => $product->get_manage_stock() ? 'yes' : 'no',
);
WC_Tracks::record_event( 'product_add_publish', $properties );