autoship_update_payment_method_action_handler (function)

(  src/scheduled-orders.php) The main handler for the for updating Scheduled Orders payment methods. It takes the (Scheduled) $order_id, and the $data needed to perform the action as parameters and returns whether the update was successful or not.

Function

/**
 * The main handler for the autoship_update_order_payment_method action
 * Updates the Payment Method for the supplied order ID
 *
 * @param int $order_id       The Autoship Scheduled Order ID
 * @param mixed $data         The Data necessary to perform this action.
 * @return int|bool|WP_Error  True if successful or WR_Error|false on failure.
 */
function autoship_update_order_payment_method_action_handler( $order_id, $data ){

  //Verify it needs to be updated if possible
  if ( isset( $data['original_autoship_order'] ) && !empty( $data['original_autoship_order'] ) ) {

    // Check to see if the payment method should be updated.
    if ( $data['autoship_order_payment_method'] == $data['original_autoship_order']['paymentMethodId'] ){

      do_action( 'autoship_after_update_scheduled_order_payment_method_handler_nochange', $order_id, $action , $data );
      wc_add_notice( __( sprintf( 'No changes needed for the Payment Method for %s #%s.', autoship_translate_text( 'Scheduled Order' ), $order_id ), 'autoship' ), 'notice' );
      return true;

    }

  }

  // Run the Set method
  // Method returns WP_Error on failure.
  return autoship_set_scheduled_order_payment_method ( $order_id, $data['autoship_order_payment_method'] );

}