Automattic\WooCommerce\Internal\EmailEditor\WCTransactionalEmails
WCEmailTemplateSelectiveApplier::restore_meta_from_snapshot
Restore one post meta from a snapshot entry. Empty prior values delete the meta rather than writing an empty string; missing keys (older snapshot format) no-op.
Method of the class: WCEmailTemplateSelectiveApplier{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = WCEmailTemplateSelectiveApplier::restore_meta_from_snapshot( $post_id, $snapshot, $snapshot_key, $post_meta_key ): void;
- $post_id(int) (required)
- The post ID.
- $snapshot(array) (required)
- .
- $snapshot_key(string) (required)
- The key inside the snapshot array.
- $post_meta_key(string) (required)
- The post meta key to write back to.
WCEmailTemplateSelectiveApplier::restore_meta_from_snapshot() WCEmailTemplateSelectiveApplier::restore meta from snapshot code WC 10.9.1
private static function restore_meta_from_snapshot( int $post_id, array $snapshot, string $snapshot_key, string $post_meta_key ): void {
if ( ! array_key_exists( $snapshot_key, $snapshot ) ) {
return;
}
$value = (string) $snapshot[ $snapshot_key ];
if ( '' !== $value ) {
update_post_meta( $post_id, $post_meta_key, $value );
} else {
delete_post_meta( $post_id, $post_meta_key );
}
}