WC_Products_Tracking::track_product_published()publicWC 1.0

Send a Tracks event when a product is published.

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

Хуки из метода

Возвращает

null. Ничего (null).

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

$WC_Products_Tracking = new WC_Products_Tracking();
$WC_Products_Tracking->track_product_published( $post_id, $post, $update, $post_before );
$post_id(int) (обязательный)
Post ID.
$post(WP_Post) (обязательный)
Post object.
$update(true|false) (обязательный)
Whether this is an existing post being updated.
$post_before(null|WP_Post) (обязательный)
Null for new posts, the WP_Post object prior to the update for updated posts.

Код WC_Products_Tracking::track_product_published() WC 8.7.0

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', '' ),
		'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',
	);

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