Home / APIs / Abstract_WC_Order_Data_Store_CPT::update_post_meta() – Helper method that updates all the post meta for an order based on it’s settings in the WC_Order class.

Description

Helper method that updates all the post meta for an order based on it's settings in the WC_Order class.

Usage

Abstract_WC_Order_Data_Store_CPT::update_post_meta( $order );

Parameters

$order
( mixed ) required –

Returns

void

Source

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

  protected function update_post_meta( &$order ) {
    $updated_props     = array();
    $meta_key_to_props = array(
      '_order_currency'     => 'currency',
      '_cart_discount'      => 'discount_total',
      '_cart_discount_tax'  => 'discount_tax',
      '_order_shipping'     => 'shipping_total',
      '_order_shipping_tax' => 'shipping_tax',
      '_order_tax'          => 'cart_tax',
      '_order_total'        => 'total',
      '_order_version'      => 'version',
      '_prices_include_tax' => 'prices_include_tax',
    );

    $props_to_update = $this->get_props_to_update( $order, $meta_key_to_props );

    foreach ( $props_to_update as $meta_key => $prop ) {
      $value = $order->{"get_$prop"}( 'edit' );

      if ( 'prices_include_tax' === $prop ) {
        $value = $value ? 'yes' : 'no';
      }

      if ( update_post_meta( $order->get_id(), $meta_key, $value ) ) {
        $updated_props[] = $prop;
      }
    }

    do_action( 'woocommerce_order_object_updated_props', $order, $updated_props );
  }
 

 View on GitHub View on Trac

Called by

1 to 2 of 2

  • Abstract_WC_Order_Data_Store_CPT::create() – Method to create a new order in the database.
  • Abstract_WC_Order_Data_Store_CPT::update() – Method to update an order in the database.

Invoked by

    Calls

    1 to 2 of 2

    • do_action() – Execute functions hooked on a specific action hook.
    • update_post_meta() – Update post meta field based on post ID.

    Call hooks

    1 to 1 of 1

    • woocommerce_order_object_updated_props – action
    Function name: Abstract_WC_Order_Data_Store_CPT::update_post_meta
    Class ref: Abstract_WC_Order_Data_Store_CPT
    Plugin ref: WooCommerce
    Version: 3.2.4
    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

    Published: 14th March 2017 | Last updated: 14th March 2017

    Information

    Function name: Abstract_WC_Order_Data_Store_CPT::update_post_meta
    Class ref: Abstract_WC_Order_Data_Store_CPT
    Plugin ref: WooCommerce
    Version: 3.2.4
    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

    • Plugins
    • Themes
    • Shortcodes
    • APIs
    • Files
    • Hooks
    • Classes
    • Sites
    • Sitemap
    • Blog
    WooCommerce a2z WooCommerce a2z
    WooCommerce

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


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