WC_Abstract_Order::save()publicWC 3.0.0

Save data to the database.

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

Возвращает

int. order ID

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

$WC_Abstract_Order = new WC_Abstract_Order();
$WC_Abstract_Order->save();

Список изменений

С версии 3.0.0 Введена.

Код WC_Abstract_Order::save() WC 6.9.1

public function save() {
	if ( ! $this->data_store ) {
		return $this->get_id();
	}

	try {
		/**
		 * 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 );

		if ( $this->get_id() ) {
			$this->data_store->update( $this );
		} else {
			$this->data_store->create( $this );
		}

		$this->save_items();

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

	} catch ( Exception $e ) {
		$message_id = $this->get_id() ? $this->get_id() : __( '(no ID)', 'woocommerce' );
		$this->handle_exception(
			$e,
			wp_kses_post(
				sprintf(
					/* translators: 1: Order ID or "(no ID)" if not known. */
					__( 'Error saving order ID %1$s.', 'woocommerce' ),
					$message_id
				)
			)
		);
	}

	return $this->get_id();
}