/**
 * Activates ad listing order and redirects user to ad if moderation is disabled,
 * otherwise redirects user to order summary.
 *
 * @param object $order
 */
function cp_payments_handle_ad_listing_completed($order)
{
    global $cp_options;
    $ad_id = _cp_get_order_ad_id($order);
    if (!$ad_id) {
        return;
    }
    $ad_url = get_permalink($ad_id);
    $order_url = get_permalink($order->get_id());
    if ($cp_options->post_status == 'publish') {
        $order->activate();
        if (!is_admin()) {
            if (did_action('wp_head')) {
                cp_js_redirect($ad_url);
            } else {
                wp_redirect($ad_url);
            }
        }
        return;
    } else {
        wp_update_post(array('ID' => $ad_id, 'post_status' => 'pending'));
        if (!is_admin()) {
            if (did_action('wp_head')) {
                cp_js_redirect($order_url);
            } else {
                wp_redirect($order_url);
            }
        }
        return;
    }
}
Beispiel #2
0
/**
 * Retrieves the permalink for an Order ad.
 *
 * @since 3.5
 *
 * @param  $object $order The Order object.
 *
 * @return null|string The ad link or null if the Order is empty.
 */
function the_order_ad_link($order)
{
    $ad_id = _cp_get_order_ad_id($order);
    if (!$ad_id) {
        return;
    }
    $title = get_the_title($ad_id);
    $html = html('a', array('href' => esc_url(get_permalink($ad_id))), $title);
    echo $html;
}
Beispiel #3
0
/**
 * Sends email with receipt to admin after completed purchase.
 *
 * @param object $order
 *
 * @return void
 */
function cp_send_admin_receipt($order)
{
    global $cp_options;
    if (is_admin() && !defined('DOING_AJAX')) {
        return;
    }
    // allow overriding admin email receipts
    if (!apply_filters('cp_send_admin_receipt', true, $order)) {
        return;
    }
    $moderation = $cp_options->moderate_ads;
    $items_html = '';
    foreach ($order->get_items() as $item) {
        $ptype_obj = get_post_type_object($item['post']->post_type);
        if (!$ptype_obj->public) {
            continue;
        }
        if ($order->get_id() != $item['post']->ID) {
            $items_html .= html('p', html_link(get_permalink($item['post']->ID), $item['post']->post_title));
        } else {
            $items_html .= html('p', APP_Item_Registry::get_title($item['type']));
        }
    }
    $table = new APP_Order_Summary_Table($order);
    ob_start();
    $table->show();
    $table_output = ob_get_clean();
    $content = '';
    $content .= html('p', __('Dear Admin,', APP_TD));
    $content .= html('p', __('You have received payment for the following items:', APP_TD));
    $content .= $items_html;
    if ($moderation && _cp_get_order_ad_id($order)) {
        $content .= html('p', __('Please review submitted ad listing, and approve it.', APP_TD));
    }
    $content .= html('p', __('Order Summary:', APP_TD));
    $content .= $table_output;
    $blogname = wp_specialchars_decode(get_bloginfo('name'), ENT_QUOTES);
    $subject = sprintf(__('[%1$s] Received payment for order #%2$d', APP_TD), $blogname, $order->get_id());
    $email = array('to' => get_option('admin_email'), 'subject' => $subject, 'message' => $content);
    $email = apply_filters('cp_email_admin_receipt', $email, $order);
    appthemes_send_email($email['to'], $email['subject'], $email['message']);
}