Skip to content

Instantly share code, notes, and snippets.

@pippinsplugins
Created March 25, 2014 21:01
Show Gist options
  • Save pippinsplugins/9771238 to your computer and use it in GitHub Desktop.
Save pippinsplugins/9771238 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: Update Previous Order Numbers for EDD
* Description: For users of the sequential order number beta, use this before you get new orders to have your previous orders sequentially numbered
* Version: 0.1
* Author: Chris Christoff
* Author URI: http://www.chriscct7.com
*/
function update_script_edd_seq_numbers(){
if( ! isset( $_GET['edd_order_upgrade'] ) ) {
return;
}
$args = array (
'post_type' => 'edd_payment', // we only want orders
'posts_per_page'=> -1, // get all the orders at once
'order' => 'ID', // same as below
'orderby' => 'ASC', // we want to order the smallest order as order #1
'fields' => 'ids', // we just need the ids
);
$orders = new WP_Query( $args ); // we hath the orders
$current_order_number = 1; // first order is #1
$prefix = ''; // stuff before the number
$postfix = ''; // stuff after the number
foreach($orders as $order){ // let's renumber all orders
$order_number = $prefix.$current_order_number.$postfix; // here's the new order number
update_post_meta($order,'_edd_payment_number', $order_number); // let's update that order
$current_order_number++; // increment the order number
}
}
add_action( 'admin_init', 'update_script_edd_seq_numbers' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment