WC_Data_Store_WP::get_props_to_update()protectedWC 1.0

Gets a list of props and meta keys that need updated based on change state or if they are present in the database or not.

Method of the class: WC_Data_Store_WP{}

No Hooks.

Return

Array. A mapping of meta keys => prop names, filtered by ones that should be updated.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_props_to_update( $object, $meta_key_to_props, $meta_type );
$object(WC_Data) (required)
The WP_Data object (WC_Coupon for coupons, etc).
$meta_key_to_props(array) (required)
A mapping of meta keys => prop names.
$meta_type(string)
The internal WP meta type (post, user, etc).
Default: 'post'

WC_Data_Store_WP::get_props_to_update() code WC 8.7.0

protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
	$props_to_update = array();
	$changed_props   = $object->get_changes();

	// Props should be updated if they are a part of the $changed array or don't exist yet.
	foreach ( $meta_key_to_props as $meta_key => $prop ) {
		if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
			$props_to_update[ $meta_key ] = $prop;
		}
	}

	return $props_to_update;
}