WC_Data::__clone
When the object is cloned, make sure meta is cloned correctly.
Meta ID handling depends on the clone mode:
- CLONE_MODE_DUPLICATE (default): Forces reading of Meta and clears meta IDs for duplication (backward compatible).
- CLONE_MODE_CACHE: Preserves meta IDs for caching purposes.
Method of the class: WC_Data{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Data = new WC_Data(); $WC_Data->__clone();
Changelog
| Since 3.0.2 | Introduced. |
WC_Data::__clone() WC Data:: clone code WC 10.8.1
public function __clone() {
if ( self::CLONE_MODE_DUPLICATE === $this->clone_mode ) {
$this->maybe_read_meta_data();
}
if ( ! empty( $this->meta_data ) ) {
foreach ( $this->meta_data as $array_key => $meta ) {
$this->meta_data[ $array_key ] = clone $meta;
// Only clear meta IDs in duplicate mode (maintains backward compatibility).
if ( self::CLONE_MODE_DUPLICATE === $this->clone_mode && ! empty( $meta->id ) ) {
$this->meta_data[ $array_key ]->id = null;
}
}
}
}