WC_Payment_Token_Data_Store::update()
Update a payment token.
Method of the class: WC_Payment_Token_Data_Store{}
Hooks from the method
Return
null
. Nothing (null).
Usage
$WC_Payment_Token_Data_Store = new WC_Payment_Token_Data_Store(); $WC_Payment_Token_Data_Store->update( $token );
- $token(WC_Payment_Token) (required) (passed by reference — &)
- Payment token object.
Changelog
Since 3.0.0 | Introduced. |
WC_Payment_Token_Data_Store::update() WC Payment Token Data Store::update code WC 9.4.2
public function update( &$token ) { if ( false === $token->validate() ) { throw new Exception( __( 'Invalid or missing payment token fields.', 'woocommerce' ) ); } global $wpdb; $updated_props = array(); $core_props = array( 'gateway_id', 'token', 'user_id', 'type' ); $changed_props = array_keys( $token->get_changes() ); foreach ( $changed_props as $prop ) { if ( ! in_array( $prop, $core_props, true ) ) { continue; } $updated_props[] = $prop; $payment_token_data[ $prop ] = $token->{'get_' . $prop}( 'edit' ); } if ( ! empty( $payment_token_data ) ) { $wpdb->update( $wpdb->prefix . 'woocommerce_payment_tokens', $payment_token_data, array( 'token_id' => $token->get_id() ) ); } $updated_extra_props = $this->save_extra_data( $token ); $updated_props = array_merge( $updated_props, $updated_extra_props ); $token->save_meta_data(); $token->apply_changes(); // Make sure all other tokens are not set to default. if ( $token->is_default() && $token->get_user_id() > 0 ) { WC_Payment_Tokens::set_users_default( $token->get_user_id(), $token->get_id() ); } do_action( 'woocommerce_payment_token_object_updated_props', $token, $updated_props ); do_action( 'woocommerce_payment_token_updated', $token->get_id() ); }