false, 'tax_class' => '', ), is_array( $data['type_config'] ?? null ) ? $data['type_config'] : array(), is_array( $data['conditions'] ?? null ) ? array_values( $data['conditions'] ) : array(), is_array( $data['meta'] ?? null ) ? $data['meta'] : array() ); } /** * Array representation (storage and REST). */ public function to_array(): array { return array( 'id' => $this->id, 'status' => $this->status, 'type' => $this->type, 'label' => $this->label, 'description' => $this->description, 'required' => $this->required, 'position' => $this->position, 'locations' => $this->locations, 'pricing' => $this->pricing, 'tax' => $this->tax, 'type_config' => $this->type_config, 'conditions' => $this->conditions, 'meta' => $this->meta, ); } /** * Returns a copy with some fields changed (used by A/B variants in the Pro). * * @param array $changes Field => value. */ public function with( array $changes ): self { return self::from_array( array_merge( $this->to_array(), $changes ) ); } /** * Copy with another label. * * @param string $label Label. */ public function with_label( string $label ): self { return $this->with( array( 'label' => $label ) ); } /** * Copy with another pricing block. * * @param array $pricing Pricing block. */ public function with_pricing( array $pricing ): self { return $this->with( array( 'pricing' => $pricing ) ); } /** * Whether the extra is active. */ public function is_active(): bool { return 'active' === $this->status; } /** * Whether the extra is taxable. */ public function is_taxable(): bool { return ! empty( $this->tax['taxable'] ); } /** * Tax class slug ('' = standard). */ public function tax_class(): string { return (string) ( $this->tax['tax_class'] ?? '' ); } }