WC_Product::save()
Save data (either create or update depending on if we are working on an existing product).
Метод класса: WC_Product{}
Хуки из метода
Возвращает
int
.
Использование
$WC_Product = new WC_Product(); $WC_Product->save();
Список изменений
С версии 3.0.0 | Введена. |
Код WC_Product::save() WC Product::save WC 9.2.3
public function save() { $this->validate_props(); if ( ! $this->data_store ) { return $this->get_id(); } /** * Trigger action before saving to the DB. Allows you to adjust object props before save. * * @param WC_Data $this The object being saved. * @param WC_Data_Store_WP $data_store THe data store persisting the data. */ do_action( 'woocommerce_before_' . $this->object_type . '_object_save', $this, $this->data_store ); $state = $this->before_data_store_save_or_update(); if ( $this->get_id() ) { $changeset = $this->get_changes(); $this->data_store->update( $this ); } else { $changeset = null; $this->data_store->create( $this ); } $this->after_data_store_save_or_update( $state ); // Update attributes lookup table if the product is new OR it's not but there are actually any changes. if ( is_null( $changeset ) || ! empty( $changeset ) ) { wc_get_container()->get( ProductAttributesLookupDataStore::class )->on_product_changed( $this, $changeset ); } /** * Trigger action after saving to the DB. * * @param WC_Data $this The object being saved. * @param WC_Data_Store_WP $data_store THe data store persisting the data. */ do_action( 'woocommerce_after_' . $this->object_type . '_object_save', $this, $this->data_store ); return $this->get_id(); }