WC_REST_Payment_Gateways_V2_Controller::update_item()
Update A Single Payment Method.
Method of the class: WC_REST_Payment_Gateways_V2_Controller{}
Hooks from the method
Return
WP_REST_Response|WP_Error
.
Usage
$WC_REST_Payment_Gateways_V2_Controller = new WC_REST_Payment_Gateways_V2_Controller(); $WC_REST_Payment_Gateways_V2_Controller->update_item( $request );
- $request(WP_REST_Request) (required)
- Request data.
WC_REST_Payment_Gateways_V2_Controller::update_item() WC REST Payment Gateways V2 Controller::update item code WC 9.3.1
public function update_item( $request ) { $gateway = $this->get_gateway( $request ); if ( is_null( $gateway ) ) { return new WP_Error( 'woocommerce_rest_payment_gateway_invalid', __( 'Resource does not exist.', 'woocommerce' ), array( 'status' => 404 ) ); } // Get settings. $gateway->init_form_fields(); $settings = $gateway->settings; // Update settings. if ( isset( $request['settings'] ) ) { $errors_found = false; foreach ( $gateway->form_fields as $key => $field ) { if ( isset( $request['settings'][ $key ] ) ) { if ( is_callable( array( $this, 'validate_setting_' . $field['type'] . '_field' ) ) ) { $value = $this->{'validate_setting_' . $field['type'] . '_field'}( $request['settings'][ $key ], $field ); } else { $value = $this->validate_setting_text_field( $request['settings'][ $key ], $field ); } if ( is_wp_error( $value ) ) { $errors_found = true; break; } $settings[ $key ] = $value; } } if ( $errors_found ) { return new WP_Error( 'rest_setting_value_invalid', __( 'An invalid setting value was passed.', 'woocommerce' ), array( 'status' => 400 ) ); } } // Update if this method is enabled or not. if ( isset( $request['enabled'] ) ) { $settings['enabled'] = wc_bool_to_string( $request['enabled'] ); $gateway->enabled = $settings['enabled']; } // Update title. if ( isset( $request['title'] ) ) { $settings['title'] = $request['title']; $gateway->title = $settings['title']; } // Update description. if ( isset( $request['description'] ) ) { $settings['description'] = $request['description']; $gateway->description = $settings['description']; } // Update options. $gateway->settings = $settings; update_option( $gateway->get_option_key(), apply_filters( 'woocommerce_gateway_' . $gateway->id . '_settings_values', $settings, $gateway ) ); // Update order. if ( isset( $request['order'] ) ) { $order = (array) get_option( 'woocommerce_gateway_order' ); $order[ $gateway->id ] = $request['order']; update_option( 'woocommerce_gateway_order', $order ); $gateway->order = absint( $request['order'] ); } $gateway = $this->prepare_item_for_response( $gateway, $request ); return rest_ensure_response( $gateway ); }