/**
 * Upgrades orders using the old item structure
 * @return void
 */
function appthemes_upgrade_item_addons()
{
    // Get All Orders
    $posts = new WP_Query(array('post_type' => APPTHEMES_ORDER_PTYPE, 'nopaging' => true));
    foreach ($posts->posts as $order) {
        $connected = new WP_Query(array('connected_type' => APPTHEMES_ORDER_CONNECTION, 'connected_from' => $order->ID));
        // Get all items
        foreach ($connected->posts as $post) {
            $post_id = $post->ID;
            // Get all addons
            $meta = p2p_get_meta($post->p2p_id);
            // Don't upgrade new items
            if (isset($meta['type'])) {
                continue;
            }
            if (isset($meta['addon'])) {
                foreach ($meta['addon'] as $addon) {
                    // Add an item for each addon
                    $p2p_id = p2p_type(APPTHEMES_ORDER_CONNECTION)->connect($order->ID, $post_id);
                    // Add meta data
                    p2p_add_meta($p2p_id, 'type', $addon);
                    p2p_add_meta($p2p_id, 'price', $meta[$addon][0]);
                }
            }
            // Add an item for the regular item
            $p2p_id = p2p_type(APPTHEMES_ORDER_CONNECTION)->connect($order->ID, $post_id);
            p2p_add_meta($p2p_id, 'type', 'regular');
            // value of VA_ITEM_REGULAR, since upgrade is only Vantage-applicable
            p2p_add_meta($p2p_id, 'price', $meta['price'][0]);
            // Delete the old item
            p2p_delete_connection($post->p2p_id);
        }
    }
}
Example #2
0
/**
 * Delete one or more connections.
 *
 * @param int $p2p_type A valid connection type.
 * @param array $args Connection information.
 *
 * @return int Number of connections deleted
 */
function p2p_delete_connections($p2p_type, $args = array())
{
    $args['fields'] = 'p2p_id';
    return p2p_delete_connection(p2p_get_connections($p2p_type, $args));
}
Example #3
0
 public function remove_item_by_id($unique_id)
 {
     p2p_delete_connection($unique_id);
     foreach ($this->items as $key => $item) {
         if ($item['unique_id'] == $unique_id) {
             unset($this->items[$key]);
             return true;
         }
     }
     return false;
 }
 function unlink()
 {
     p2p_delete_connection($this->p2p_id);
 }
Example #5
0
 public function ajax_disconnect()
 {
     p2p_delete_connection($_POST['p2p_id']);
     $this->refresh_candidates();
 }
Example #6
0
 public function ajax_disconnect()
 {
     p2p_delete_connection($_POST['p2p_id']);
     die(1);
 }