• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / Abstract_WC_Order_Data_Store_CPT::update() – Method to update an order in the database.

You appear to be a bot. Output may be restricted

Description

Method to update an order in the database.

Usage

Abstract_WC_Order_Data_Store_CPT::update( $order );

Parameters

$order
( WC_Order ) required – Order object.

Returns

void

Source

File name: woocommerce/includes/data-stores/abstract-wc-order-data-store-cpt.php
Lines:

1 to 42 of 42
  public function update( &$order ) {
    $order->save_meta_data();
    $order->set_version( Constants::get_constant( 'WC_VERSION' ) );

    if ( null === $order->get_date_created( 'edit' ) ) {
      $order->set_date_created( time() );
    }

    $changes = $order->get_changes();

    // Only update the post when the post data changes.
    if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
      $post_data = array(
        'post_date'         => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
        'post_date_gmt'     => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
        'post_status'       => $this->get_post_status( $order ),
        'post_parent'       => $order->get_parent_id(),
        'post_excerpt'      => $this->get_post_excerpt( $order ),
        'post_modified'     => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : current_time( 'mysql' ),
        'post_modified_gmt' => isset( $changes['date_modified'] ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getTimestamp() ) : current_time( 'mysql', 1 ),
      );

      
/**
 * When updating this object, to prevent infinite loops, use $wpdb
 * to update data, since wp_update_post spawns more calls to the
 * save_post action.
 *
 * This ensures hooks are fired by either WP itself (admin screen save),
 * or an update purely from CRUD.
 */
      if ( doing_action( 'save_post' ) ) {
        $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $order->get_id() ) );
        clean_post_cache( $order->get_id() );
      } else {
        wp_update_post( array_merge( array( 'ID' => $order->get_id() ), $post_data ) );
      }
      $order->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
    }
    $this->update_post_meta( $order );
    $order->apply_changes();
    $this->clear_caches( $order );
  }
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 6th April 2020

Primary Sidebar

Information

Function name: Abstract_WC_Order_Data_Store_CPT::update
Class ref: Abstract_WC_Order_Data_Store_CPT
Plugin ref: WooCommerce
Version: 5.2.2
Sourcefile: includes/data-stores/abstract-wc-order-data-store-cpt.php
File ref: includes/data-stores/abstract-wc-order-data-store-cpt.php
Deprecated?: No
API Letters: A,D,O,S,W

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites