autoship_update_order_shipping_address_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_shipping_address action
 * Updates the Shipping Address 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_shipping_address_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 address should be updated.
    $current_address = autoship_order_address_values( $autoship_order, 'shipping' );

    $changed = false;
    // Run through the current Scheduled Order Address Fields and look for changes.
    foreach ( $current_address as $key => $value) {

      if ( isset( $data['shipping_address'][$key] ) && ( $value != $data['shipping_address'][$key] ) ){
        $changed = true;
        break;
      }

    }

    // If none of the existing values changed and no new fields were added then no-change.
    if ( !$changed && ( array_merge( $current_address, $data['shipping_address'] ) == count( $current_address ) ) ){

      do_action( 'autoship_after_update_scheduled_order_shipping_address_handler_nochange', $order_id, $action , $data );
      wc_add_notice( __( sprintf( 'No changes updated for %s #%s.', autoship_translate_text( 'Scheduled Order' ), $order_id ), 'autoship' ), 'notice' );
      return true;

    }

  }

  if ( !isset( $data['original_autoship_order'] ) || empty( $data['original_autoship_order'] ) ){
  $data['original_autoship_order'] = autoship_get_scheduled_orders( $order_id );
  $data['original_autoship_order'] = autoship_convert_object_to_array( $data['original_autoship_order'] ); }

  // Run the update method
  // Method returns WP_Error on failure.
  return autoship_set_scheduled_order_shipping_address ( $data['original_autoship_order'], $data['shipping_address'] );

}