Example #1
0
function accesspress_create_order($member, $order_details)
{
    $renewal = !empty($order_details['_acp_order_id']);
    if ($renewal) {
        $order = $order_details['_acp_order_id'];
        unset($order_details['_acp_order_id']);
    } else {
        /** Create Order */
        $order = wp_insert_post(array('post_title' => $order_details['_acp_order_time'], 'post_status' => 'publish', 'post_type' => 'acp-orders', 'ping_status' => 0, 'post_parent' => 0, 'menu_order' => 0));
        /** Bail, if there's a problem */
        if (is_wp_error($order)) {
            return $order;
        }
    }
    /** Complete order information from $order_details array */
    foreach ((array) $order_details as $key => $value) {
        update_post_meta((int) $order, $key, $value);
    }
    /** Add Order ID to user meta */
    memberaccess_add_order_to_member($member, $order);
    do_action('premise_membership_create_order', $member, $order_details, $renewal);
    /** Return Order ID and Member ID on success */
    return array('order_id' => $order, 'member_id' => $member);
}
Example #2
0
 /**
  * Save the form data from the metaboxes
  */
 function metabox_save($post_id, $post)
 {
     global $memberaccess_products_object;
     /**	Verify the nonce */
     if (!isset($_POST['accesspress-orders-nonce']) || !wp_verify_nonce($_POST['accesspress-orders-nonce'], plugin_basename(__FILE__))) {
         return $post->ID;
     }
     /**	Don't try to save the data under autosave, ajax, or future post */
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     if (defined('DOING_CRON') && DOING_CRON) {
         return;
     }
     /**	Check if user is allowed to edit this */
     if (!current_user_can('edit_post', $post->ID)) {
         return $post->ID;
     }
     /** Merge defaults with user submission */
     $values = wp_parse_args($_POST['accesspress_order_meta'], array('_acp_order_time' => '', '_acp_order_status' => '', '_acp_order_product_id' => '', '_acp_order_member_id' => '', '_acp_order_complimentary' => ''));
     if ($values['_acp_order_product_id']) {
         if ((int) $values['_acp_order_product_id']) {
             $product = get_post($values['_acp_order_product_id']);
             if (empty($product) || 'acp-products' != $product->post_type) {
                 $product = false;
             }
         }
         if (!$product) {
             $products = new WP_query(array('post_type' => 'acp-products', 'name' => $values['_acp_order_product_id']));
             if ($products->have_posts()) {
                 $products->the_post();
                 $values['_acp_order_product_id'] = get_the_ID();
             } else {
                 $values['_acp_order_product_id'] = '';
             }
             wp_reset_query();
         }
     }
     /** Sanitize */
     $values = $this->sanitize($values);
     /** simulate checkout on comp order */
     if ($values['_acp_order_complimentary']) {
         $user = get_user_by('id', $values['_acp_order_member_id']);
         if (!empty($user)) {
             $user_data = get_object_vars($user->data);
             do_action('premise_create_member', $values['_acp_order_member_id'], $user_data);
             // don't send the comp'ed user a receipt
             remove_action('premise_membership_create_order', array($memberaccess_products_object, 'email_purchase_notification'), 10, 2);
             do_action('premise_membership_create_order', $values['_acp_order_member_id'], $values, false);
         }
     }
     unset($values['_acp_order_complimentary']);
     /** Loop through values, update post meta */
     $meta_update = false;
     foreach ((array) $values as $key => $value) {
         if ($value) {
             update_post_meta($post->ID, $key, $value);
             $meta_update = true;
         }
     }
     if ($meta_update) {
         memberaccess_add_order_to_member($values['_acp_order_member_id'], $post->ID);
     }
 }