WC_Data_Store_WP::get_props_to_update( WC_Data $object, array $meta_key_to_props, string $meta_type = 'post' )

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.


Description Description


Parameters Parameters

$object

(Required) The WP_Data object (WC_Coupon for coupons, etc).

$meta_key_to_props

(Required) A mapping of meta keys => prop names.

$meta_type

(Optional) The internal WP meta type (post, user, etc).

Default value: 'post'


Top ↑

Return Return

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


Top ↑

Source Source

File: includes/data-stores/class-wc-data-store-wp.php

	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;
	}

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.