WC_Products_Tracking::track_product_published()publicWC 1.0

Send a Tracks event when a product is published.

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

Хуков нет.

Возвращает

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 6.9.4

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

	$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(),
		'purchase_note'     => $product->get_purchase_note() ? 'yes' : 'no',
		'sale_price'        => $product->get_sale_price() ? 'yes' : 'no',
		'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 );
}