marketplace value code. Wins over suggestions. * * @var array */ public $values = array(); /** * Constructor. * * @param array $data Rule data (type, key, fixed, values). */ public function __construct( array $data = array() ) { $type = (string) ( $data['type'] ?? self::SKIP ); if ( in_array( $type, array( self::WC_ATTRIBUTE, self::FIELD, self::FIXED, self::ASK, self::SKIP ), true ) ) { $this->type = $type; } $this->key = (string) ( $data['key'] ?? '' ); $this->fixed = (string) ( $data['fixed'] ?? '' ); foreach ( (array) ( $data['values'] ?? array() ) as $shop => $remote ) { $shop = Normalizer::key( (string) $shop ); if ( '' !== $shop && '' !== (string) $remote ) { $this->values[ $shop ] = (string) $remote; } } } /** * Rule data for storing. */ public function to_array(): array { return array( 'type' => $this->type, 'key' => $this->key, 'fixed' => $this->fixed, 'values' => $this->values, ); } /** * Shortcut: a fixed value. * * @param string $value Value. */ public static function fixed( string $value ): self { return new self( array( 'type' => self::FIXED, 'fixed' => $value, ) ); } /** * Shortcut: a WooCommerce attribute. * * @param string $name Attribute name (pa_color…). */ public static function attribute( string $name ): self { return new self( array( 'type' => self::WC_ATTRIBUTE, 'key' => $name, ) ); } /** * Shortcut: a product field. * * @param string $field Field name. */ public static function field( string $field ): self { return new self( array( 'type' => self::FIELD, 'key' => $field, ) ); } }