WC_Data::set_props( array $props, string $context = 'set' )
Set a collection of props in one go, collect any errors, and return the result.
Description Description
Only sets using public methods.
Parameters Parameters
- $props
-
(Required) Key value pairs to set. Key is the prop and should map to a setter function name.
- $context
-
(Optional) In what context to run this.
Default value: 'set'
Return Return
(bool|WP_Error)
Source Source
File: includes/abstracts/abstract-wc-data.php
public function set_props( $props, $context = 'set' ) { $errors = false; foreach ( $props as $prop => $value ) { try { /** * Checks if the prop being set is allowed, and the value is not null. */ if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { continue; } $setter = "set_$prop"; if ( is_callable( array( $this, $setter ) ) ) { $this->{$setter}( $value ); } } catch ( WC_Data_Exception $e ) { if ( ! $errors ) { $errors = new WP_Error(); } $errors->add( $e->getErrorCode(), $e->getMessage() ); } } return $errors && count( $errors->get_error_codes() ) ? $errors : true; }
Changelog Changelog
Version | Description |
---|---|
3.0.0 | Introduced. |