WC_Payment_Token_Data_Store::update( WC_Payment_Token $token )
Update a payment token.
Description Description
Parameters Parameters
- $token
-
(Required) Payment token object.
Source Source
File: includes/data-stores/class-wc-payment-token-data-store.php
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() );
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.0.0 | Introduced. |