| @@ -25,11 +25,26 @@ | ||
| 25 | 25 | $error = $validate_tax_ids( $payload ); |
| 26 | 26 | return is_wp_error( $error ) ? $error : parent::prepare_update( $meta, $id, $this->prepare_payload( $payload ), $validate_tax_ids ); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - /** Persist customer tax IDs after successful writes and poison recovery. */ | |
| 30 | - public function persist( string $phase, int $id, array $payload, array $current = array(), array $response_data = array(), array $context = array() ): void { | |
| 31 | - if ( ! in_array( $phase, array( 'create_before_identity', 'create_recovery', 'update' ), true ) || $id <= 0 || ! is_array( $payload['tax_ids'] ?? null ) ) { | |
| 29 | + /** Persist customer tax IDs after create. */ | |
| 30 | + public function after_create( int $id, array $payload ): void { | |
| 31 | + $this->write_tax_ids( $id, $payload ); | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** Persist customer tax IDs after recovery. */ | |
| 35 | + public function after_recovery( int $id, array $payload ): void { | |
| 36 | + $this->write_tax_ids( $id, $payload ); | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** Persist customer tax IDs after update. */ | |
| 40 | + public function after_update( int $id, array $payload, array $current, array $response_data, array $context ): void { | |
| 41 | + $this->write_tax_ids( $id, $payload ); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** The one tax-ID write every lifecycle phase shares; identity itself never carries tax ids. */ | |
| 45 | + private function write_tax_ids( int $id, array $payload ): void { | |
| 46 | + if ( $id <= 0 || ! is_array( $payload['tax_ids'] ?? null ) ) { | |
| 32 | 47 | return; |
| 33 | 48 | } |
| 34 | 49 | ( new Tax_Id_Writer() )->write_for_user( $id, $payload['tax_ids'] ); |
| 35 | 50 | } |