WC_Products_Tracking::track_product_published()
Send a Tracks event when a product is published.
Method of the class: WC_Products_Tracking{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Products_Tracking = new WC_Products_Tracking(); $WC_Products_Tracking->track_product_published( $post_id, $post, $update, $post_before );
- $post_id(int) (required)
- Post ID.
- $post(WP_Post) (required)
- Post object.
- $update(true|false) (required)
- Whether this is an existing post being updated.
- $post_before(null|WP_Post) (required)
- Null for new posts, the WP_Post object prior to the update for updated posts.
WC_Products_Tracking::track_product_published() WC Products Tracking::track product published code WC 9.8.2
public function track_product_published( $post_id, $post, $update, $post_before ) { if ( 'product' !== $post->post_type || 'publish' !== $post->post_status || ( $post_before && 'publish' === $post_before->post_status ) ) { return; } $product = wc_get_product( $post_id ); $product_type_options = self::get_product_type_options( $post_id ); $product_type_options_string = self::get_product_type_options_string( $product_type_options ); $properties = array( 'attributes' => count( $product->get_attributes() ), 'categories' => count( $product->get_category_ids() ), 'cross_sells' => ! empty( $product->get_cross_sell_ids() ) ? 'yes' : 'no', 'description' => $product->get_description() ? 'yes' : 'no', 'dimensions' => wc_format_dimensions( $product->get_dimensions( false ) ) !== 'N/A' ? 'yes' : 'no', 'enable_reviews' => $product->get_reviews_allowed() ? 'yes' : 'no', 'is_downloadable' => $product->is_downloadable() ? 'yes' : 'no', 'is_virtual' => $product->is_virtual() ? 'yes' : 'no', 'manage_stock' => $product->get_manage_stock() ? 'yes' : 'no', 'menu_order' => $product->get_menu_order() ? 'yes' : 'no', 'product_id' => $post_id, 'product_gallery' => count( $product->get_gallery_image_ids() ), 'product_image' => $product->get_image_id() ? 'yes' : 'no', 'product_type' => $product->get_type(), 'product_type_options' => $product_type_options_string, 'purchase_note' => $product->get_purchase_note() ? 'yes' : 'no', 'sale_price' => $product->get_sale_price() ? 'yes' : 'no', 'source' => apply_filters( 'woocommerce_product_source', self::is_importing() ? 'import' : self::TRACKS_SOURCE ), 'short_description' => $product->get_short_description() ? 'yes' : 'no', 'tags' => count( $product->get_tag_ids() ), 'upsells' => ! empty( $product->get_upsell_ids() ) ? 'yes' : 'no', 'weight' => $product->get_weight() ? 'yes' : 'no', 'global_unique_id' => $product->get_global_unique_id() ? 'yes' : 'no', ); WC_Tracks::record_event( 'product_add_publish', $properties ); }