_wpsc_ajax_update_checkout_fields_order

Update Checkout fields order.

Description

(array|WP_Error) _wpsc_ajax_update_checkout_fields_order(); 

Returns (array|WP_Error)

Response args or WP_Error


Usage

  1. if ( !function_exists( '_wpsc_ajax_update_checkout_fields_order' ) ) { 
  2. require_once '/wpsc-admin/ajax.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = _wpsc_ajax_update_checkout_fields_order(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wpsc-admin/ajax.php  
  1. function _wpsc_ajax_update_checkout_fields_order() { 
  2. global $wpdb; 
  3.  
  4. $checkout_fields = $_REQUEST['sort_order']; 
  5. $order = 1; 
  6. $failed = array(); 
  7. $modified = array(); 
  8. foreach ( $checkout_fields as &$checkout_field ) { 
  9. // ignore new fields 
  10. if ( strpos( $checkout_field, 'new-field' ) === 0 ) 
  11. continue; 
  12. $checkout_field = absint( preg_replace('/[^0-9]+/', '', $checkout_field ) ); 
  13. $result = $wpdb->update( 
  14. WPSC_TABLE_CHECKOUT_FORMS,  
  15. array( 
  16. 'checkout_order' => $order 
  17. ),  
  18. array( 
  19. 'id' => $checkout_field 
  20. ),  
  21. '%d',  
  22. '%d' 
  23. ); 
  24. $order ++; 
  25. if ( $result === false ) 
  26. $failed[] = $checkout_field; 
  27. elseif ( $result > 0 ) 
  28. $modified[] = $checkout_field; 
  29.  
  30. if ( ! empty( $failed ) ) 
  31. return new WP_Error( 'wpsc_cannot_save_checkout_field_sort_order', __( "Couldn't save checkout field sort order. Please try again.", 'wpsc' ), array( 'failed_ids' => $failed ) ); 
  32.  
  33. return array( 
  34. 'modified' => $modified,  
  35. );