WC_Post_Data::product_type_changed()
Handle type changes.
Метод класса: WC_Post_Data{}
Хуки из метода
Возвращает
null
. Ничего (null).
Использование
$result = WC_Post_Data::product_type_changed( $product, $from, $to );
- $product(WC_Product) (обязательный)
- Product data.
- $from(строка) (обязательный)
- Origin type.
- $to(строка) (обязательный)
- New type.
Список изменений
С версии 3.0.0 | Введена. |
Код WC_Post_Data::product_type_changed() WC Post Data::product type changed WC 9.4.2
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 ); } }