WordPress at a glance
function is not described

WC_Post_Data::product_type_changed() public WC 3.0.0

Handle type changes.

{} It's a method of the class: WC_Post_Data{}

Return

null. Nothing.

Usage

$result = WC_Post_Data::product_type_changed( $product, $from, $to );
$product(WC_Product) (required)
Product data.
$from(string) (required)
Origin type.
$to(string) (required)
New type.

Changelog

Since 3.0.0 Introduced.

Code of WC_Post_Data::product_type_changed() WC 5.3.0

<?php
public static function product_type_changed( $product, $from, $to ) {
	/**
	 * Filter to prevent variations from being deleted while switching from a variable product type to a variable product type.
	 *
	 * @since 5.0.0
	 *
	 * @param bool       A boolean value of true will delete the variations.
	 * @param WC_Product $product Product data.
	 * @return string    $from    Origin type.
	 * @param string     $to      New type.
	 */
	if ( apply_filters( 'woocommerce_delete_variations_on_product_type_change', 'variable' === $from && 'variable' !== $to, $product, $from, $to ) ) {
		// If the product is no longer variable, we should ensure all variations are removed.
		$data_store = WC_Data_Store::load( 'product-variable' );
		$data_store->delete_variations( $product->get_id(), true );
	}
}