Пример #1
0
/**
 * Purchase Link Shortcode
 *
 * Retrieves a download and displays the purchase form.
 *
 * @since 1.0
 * @param array $atts Shortcode attributes
 * @param string $content
 * @return string Fully formatted purchase link
 */
function edd_download_shortcode($atts, $content = null)
{
    global $post;
    $post_id = is_object($post) ? $post->ID : 0;
    $atts = shortcode_atts(array('id' => $post_id, 'price_id' => isset($atts['price_id']) ? $atts['price_id'] : false, 'sku' => '', 'price' => '1', 'direct' => '0', 'text' => '', 'style' => edd_get_option('button_style', 'button'), 'color' => edd_get_option('checkout_color', 'blue'), 'class' => 'edd-submit', 'form_id' => ''), $atts, 'purchase_link');
    // Override text only if not provided / empty
    if (!$atts['text']) {
        if ($atts['direct'] == '1' || $atts['direct'] == 'true') {
            $atts['text'] = edd_get_option('buy_now_text', __('Buy Now', 'easy-digital-downloads'));
        } else {
            $atts['text'] = edd_get_option('add_to_cart_text', __('Purchase', 'easy-digital-downloads'));
        }
    }
    // Override color if color == inherit
    if (isset($atts['color'])) {
        $atts['color'] = $atts['color'] == 'inherit' ? '' : $atts['color'];
    }
    if (!empty($atts['sku'])) {
        $download = edd_get_download_by('sku', $atts['sku']);
        $atts['download_id'] = $download->ID;
    } elseif (isset($atts['id'])) {
        // Edd_get_purchase_link() expects the ID to be download_id since v1.3
        $atts['download_id'] = $atts['id'];
        $download = edd_get_download($atts['download_id']);
    }
    if ($download) {
        return edd_get_purchase_link($atts);
    }
}
/**
 * Purchase Link Shortcode
 *
 * Retrieves a download and displays the purchase form.
 *
 * @access      private
 * @since       1.0 
 * @return      string
*/
function edd_download_shortcode($atts, $content = null)
{
    extract(shortcode_atts(array('id' => '', 'text' => __('Purchase', 'edd'), 'style' => 'button', 'color' => 'blue', 'class' => ''), $atts));
    $download = edd_get_download($id);
    if ($download) {
        return edd_get_purchase_link($download->ID, $text, $style, $color, $class);
    }
}
/**
 * Purchase Link Shortcode
 *
 * Retrieves a download and displays the purchase form.
 *
 * @since 1.0
 * @param array $atts Shortcode attributes
 * @param string $content
 * @return string Fully formatted purchase link
 */
function edd_download_shortcode($atts, $content = null)
{
    global $post, $edd_options;
    extract(shortcode_atts(array('id' => $post->ID, 'price' => '1', 'text' => isset($edd_options['add_to_cart_text']) && $edd_options['add_to_cart_text'] != '' ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd'), 'style' => isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button', 'color' => isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue', 'class' => 'edd-submit'), $atts));
    // Edd_get_purchase_link() expects the ID to be download_id since v1.3
    $atts['download_id'] = $atts['id'];
    $download = edd_get_download($atts['download_id']);
    if ($download) {
        return edd_get_purchase_link($atts);
    }
}
/**
 * Output free download URL
 */
function vp_edd_fd_download_shortcode($atts, $content = null)
{
    global $post, $edd_options;
    $button_text = (isset($edd_options['vp_edd_fd_button_text']) and $edd_options['vp_edd_fd_button_text'] !== '') ? $edd_options['vp_edd_fd_button_text'] : __('Download', 'vp_edd_fd');
    $button_class = (isset($edd_options['vp_edd_fd_button_class']) and $edd_options['vp_edd_fd_button_class'] !== '') ? $edd_options['vp_edd_fd_button_class'] : __('edd-fd-button', 'vp_edd_fd');
    extract(shortcode_atts(array('id' => $post->ID, 'text' => $button_text, 'class' => $button_class), $atts));
    $download = edd_get_download($id);
    $text = str_replace('%name%', $download->post_title, $text);
    if ($download) {
        return '<a href="' . vp_edd_fd_build_download_list_url($id) . '" class="' . $class . '">' . $text . '</a>';
    }
}
Пример #5
0
/**
 * Purchase Link Shortcode
 *
 * Retrieves a download and displays the purchase form.
 *
 * @since 1.0
 * @param array $atts Shortcode attributes
 * @param string $content
 * @return string Fully formatted purchase link
 */
function edd_download_shortcode($atts, $content = null)
{
    global $post, $edd_options;
    $post_id = is_object($post) ? $post->ID : 0;
    $atts = shortcode_atts(array('id' => $post_id, 'sku' => '', 'price' => '1', 'direct' => '0', 'text' => isset($edd_options['add_to_cart_text']) && $edd_options['add_to_cart_text'] != '' ? $edd_options['add_to_cart_text'] : __('Purchase', 'edd'), 'style' => isset($edd_options['button_style']) ? $edd_options['button_style'] : 'button', 'color' => isset($edd_options['checkout_color']) ? $edd_options['checkout_color'] : 'blue', 'class' => 'edd-submit', 'form_id' => ''), $atts, 'purchase_link');
    // Override color if color == inherit
    if (isset($atts['color'])) {
        $atts['color'] = $atts['color'] == 'inherit' ? '' : $atts['color'];
    }
    if (isset($atts['id'])) {
        // Edd_get_purchase_link() expects the ID to be download_id since v1.3
        $atts['download_id'] = $atts['id'];
        $download = edd_get_download($atts['download_id']);
    } elseif (isset($atts['sku'])) {
        $download = edd_get_download_by('sku', $atts['sku']);
        $atts['download_id'] = $download->ID;
    }
    if ($download) {
        return edd_get_purchase_link($atts);
    }
}
Пример #6
0
 /**
  * Gets an individual ticket
  *
  * @param $unused_event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($unused_event_id, $ticket_id)
 {
     $product = edd_get_download($ticket_id);
     if (!$product) {
         return null;
     }
     $return = new Tribe__Tickets__Ticket_Object();
     $purchased = $this->stock_control->get_purchased_inventory($ticket_id, array('publish'));
     $stock = '' === $product->_stock ? Tribe__Tickets__Ticket_Object::UNLIMITED_STOCK : $product->_stock;
     $return->description = $product->post_content;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->post_title;
     $return->price = $product->edd_price;
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $pending = $this->stock_control->count_incomplete_order_items($ticket_id);
     $return->manage_stock((bool) $stock);
     $return->stock($stock - $purchased - $pending);
     $return->qty_sold($purchased);
     $return->qty_pending($pending);
     return $return;
 }
/**
 * Adds post classes for downloads
 *
 * @since 2.1
 * @param array $classes Current classes
 * @param string|array $class
 * @param int $post_id The ID of the current post
 * @return array Modified array of classes
 */
function edd_add_download_post_classes($classes, $class = '', $post_id = false)
{
    if (!$post_id || get_post_type($post_id) !== 'download' || is_admin()) {
        return $classes;
    }
    $download = edd_get_download($post_id);
    if ($download) {
        $classes[] = 'edd-download';
        // Add category slugs
        $categories = get_the_terms($post_id, 'download_category');
        if (!empty($categories)) {
            foreach ($categories as $key => $value) {
                $classes[] = 'edd-download-cat-' . $value->slug;
            }
        }
        // Add tag slugs
        $tags = get_the_terms($post_id, 'download_tag');
        if (!empty($tags)) {
            foreach ($tags as $key => $value) {
                $classes[] = 'edd-download-tag-' . $value->slug;
            }
        }
        // Add edd-download
        if (is_singular('download')) {
            $classes[] = 'edd-download';
        }
    }
    return $classes;
}
 /**
  * Send purchase details to MailChimp's Ecommerce360 extension.
  *
  * @param  integer $payment_id    [description]
  * @return bool
  */
 public function record_ecommerce360_purchase($payment_id = 0)
 {
     // Make sure an API key has been entered
     if (empty($this->key)) {
         return FALSE;
     }
     // Don't record details if we're in test mode
     if (edd_is_test_mode()) {
         return FALSE;
     }
     $payment = edd_get_payment_meta($payment_id);
     $user_info = edd_get_payment_meta_user_info($payment_id);
     $amount = edd_get_payment_amount($payment_id);
     $cart_details = edd_get_payment_meta_cart_details($payment_id);
     $tax = edd_get_payment_tax($payment_id);
     if (is_array($cart_details)) {
         $items = array();
         // Increase purchase count and earnings
         foreach ($cart_details as $index => $download) {
             // Get the categories that this download belongs to, if any
             $post = edd_get_download($download['id']);
             $terms = get_the_terms($download['id'], 'download_category');
             if ($terms && !is_wp_error($terms)) {
                 $categories = array();
                 foreach ($terms as $term) {
                     $categories[] = $term->name;
                 }
                 $category_id = $terms[0]->term_id;
                 $category_name = join(" - ", $categories);
             } else {
                 $category_id = 1;
                 $category_name = 'Download';
             }
             // "bundle" or "default"
             $download_type = edd_get_download_type($download['id']);
             $download['sku'] = edd_get_download_sku($download['id']);
             // if ( 'bundle' == $download_type ) {
             //   $downloads = edd_get_bundled_products( $download_id );
             //   if ( $downloads ) {
             //     foreach ( $downloads as $d_id ) {
             //       # Do something
             //     }
             //   }
             // }
             $item = array('line_num' => $index + 1, 'product_id' => (int) $download['id'], 'product_name' => $download['name'], 'category_id' => $category_id, 'category_name' => $category_name, 'qty' => $download['quantity'], 'cost' => $download['subtotal']);
             if ($download['sku'] !== '-') {
                 $item['sku'] = $download['sku'];
                 // optional, 30 char limit
             }
             $items[] = $item;
         }
         $order = array('id' => (string) $payment_id, 'email' => $user_info['email'], 'total' => $amount, 'store_id' => self::_edd_ec360_get_store_id(), 'store_name' => home_url(), 'items' => $items, 'order_date' => get_the_date('Y-n-j', $payment_id));
         // Set Ecommerce360 variables if they exist
         $campaign_id = get_post_meta($payment_id, '_edd_mc_campaign_id', true);
         $email_id = get_post_meta($payment_id, '_edd_mc_email_id', true);
         if (!empty($campaign_id)) {
             $order['campaign_id'] = $campaign_id;
         }
         if (!empty($email_id)) {
             $order['email_id'] = $email_id;
         }
         if ($tax != 0) {
             $order['tax'] = $tax;
             // double, optional
         }
         // Send to MailChimp
         $options = array('CURLOPT_FOLLOWLOCATION' => false);
         $mailchimp = new EDD_MailChimp_API($this->key, $options);
         try {
             $result = $mailchimp->call('ecomm/order-add', array('order' => $order));
             edd_insert_payment_note($payment_id, __('Order details have been added to MailChimp successfully', 'eddmc'));
         } catch (Exception $e) {
             edd_insert_payment_note($payment_id, __('MailChimp Ecommerce360 Error: ', 'eddmc') . $e->getMessage());
             return FALSE;
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
Пример #9
0
$stock = Tribe__Tickets_Plus__Commerce__EDD__Main::get_instance()->stock();
ob_start();
?>
<h2 class="tribe-events-tickets-title"><?php 
esc_html_e('Tickets', 'event-tickets-plus');
?>
</h2>

<form action="<?php 
echo esc_url(add_query_arg('eddtickets_process', 1, edd_get_checkout_uri()));
?>
" class="cart" method="post" enctype='multipart/form-data'>
	<table width="100%" class="tribe-events-tickets">
			<?php 
foreach ($tickets as $ticket) {
    $product = edd_get_download($ticket->ID);
    if ($ticket->date_in_range(current_time('timestamp'))) {
        $is_there_any_product = true;
        $data_product_id = 'data-product-id="' . esc_attr($ticket->ID) . '"';
        echo sprintf('<input type="hidden" name="product_id[]"" value="%d">', esc_attr($ticket->ID));
        echo '<tr>';
        echo '<td width="75" class="edd quantity" data-product-id="' . esc_attr($ticket->ID) . '">';
        if ($stock->available_units($product->ID)) {
            // For global stock enabled tickets with a cap, use the cap as the max quantity
            if ($global_stock_enabled && Tribe__Tickets__Global_Stock::CAPPED_STOCK_MODE === $ticket->global_stock_mode()) {
                $remaining = $ticket->global_stock_cap();
            } else {
                $remaining = $ticket->remaining();
            }
            $max = '';
            if ($ticket->managing_stock()) {
/**
 * Process a straight-to-gateway purchase
 *
 * @since 1.7
 * @return void
 */
function edd_process_straight_to_gateway($data)
{
    $download_id = $data['download_id'];
    $options = isset($data['edd_options']) ? $data['edd_options'] : array();
    $quantity = isset($data['edd_download_quantity']) ? $data['edd_download_quantity'] : 1;
    if (empty($download_id) || !edd_get_download($download_id)) {
        return;
    }
    $purchase_data = edd_build_straight_to_gateway_data($download_id, $options, $quantity);
    edd_set_purchase_session($purchase_data);
    edd_send_to_gateway($purchase_data['gateway'], $purchase_data);
}
 } else {
     $wc_coupon = null;
 }
 // Line Items from the WC Order
 foreach ($wc_items as $item) {
     $product = $order->get_product_from_item($item);
     $item['quantity'] = $item['qty'];
     $item['data'] = $product;
     if (!isset($wc_edd_product_map[$product->id]) || empty($wc_edd_product_map[$product->id])) {
         $temp_log_str = "\nEDD Product Not available for this WC Product.\n";
         $log_str .= $temp_log_str;
         echo $temp_log_str;
         $break_loop = true;
         break;
     }
     $download = edd_get_download($wc_edd_product_map[$product->id]);
     $item_number = array('id' => $download->ID, 'options' => array(), 'quantity' => $item['qty']);
     $downloads[] = $item_number;
     $_wc_cart_disc_meta = get_post_meta($order->id, '_cart_discount', true);
     $_wc_cart_disc_meta = floatval($_wc_cart_disc_meta);
     $_wc_order_disc_meta = get_post_meta($order->id, '_order_discount', true);
     $_wc_order_disc_meta = floatval($_wc_order_disc_meta);
     // Cart Discount Logic for migration - Two Types : 1. Cart Discount 2. Product Discount
     if (!empty($_wc_cart_disc_meta)) {
         $item_price = $item['line_subtotal'];
         $discount = (floatval($item['line_subtotal']) - floatval($item['line_total'])) * $item['qty'];
         $subtotal = $item['line_subtotal'] * $item['qty'] - $discount;
         $price = $subtotal;
         // $item[ 'line_total' ]
     } else {
         $item_price = $item['line_subtotal'];
/**
 * Create license key
 *
 * @since 1.0.0
 * @return void
 */
function edd_slm_create_license_keys($payment_id)
{
    // Collect license keys
    $licenses = array();
    // Payment meta
    $payment_meta = edd_get_payment_meta($payment_id);
    //edd_slm_print_pretty($payment_meta);
    foreach ($payment_meta['cart_details'] as $item) {
        $download_id = $item['id'];
        if (edd_slm_is_licensing_enabled($download_id)) {
            // Download data
            $download_data = edd_get_download($download_id);
            if ($download_data) {
                $download_quantity = absint($item['quantity']);
                for ($i = 1; $i <= $download_quantity; $i++) {
                    // Get price id
                    $price_id = edd_get_cart_item_price_id($item);
                    $price_name = edd_get_cart_item_price_name($item);
                    // Sites allowed
                    $sites_allowed = edd_slm_get_sites_allowed($price_id, $payment_id, $download_id);
                    if (!$sites_allowed) {
                        $sites_allowed_error = __('License could not be created: Invalid sites allowed number.', 'edd-slm');
                        $int = edd_insert_payment_note($payment_id, $sites_allowed_error);
                        break;
                    }
                    // Transaction id
                    $transaction_id = edd_get_payment_transaction_id($payment_id);
                    // Build item name
                    $item_name = !empty($price_name) ? $item['name'] . ' - ' . $price_name : $item['name'];
                    // Build parameters
                    $api_params = array();
                    $api_params['slm_action'] = 'slm_create_new';
                    $api_params['secret_key'] = EDD_SLM_API_SECRET;
                    $api_params['first_name'] = isset($payment_meta['user_info']['first_name']) ? $payment_meta['user_info']['first_name'] : '';
                    $api_params['last_name'] = isset($payment_meta['user_info']['last_name']) ? $payment_meta['user_info']['last_name'] : '';
                    $api_params['email'] = isset($payment_meta['user_info']['email']) ? $payment_meta['user_info']['email'] : '';
                    $api_params['company_name'] = '';
                    $api_params['txn_id'] = $transaction_id . ' - ' . $item_name;
                    $api_params['max_allowed_domains'] = $sites_allowed;
                    $api_params['date_created'] = date('Y-m-d');
                    $api_params['date_expiry'] = '0000-00-00';
                    // Send query to the license manager server
                    $url = EDD_SLM_API_URL . '?' . http_build_query($api_params);
                    $response = wp_remote_get($url, array('timeout' => 30));
                    edd_slm_add_log('Item: ' . $item_name);
                    edd_slm_add_log('- SLM Response Body: ' . $response['body']);
                    foreach ($response['response'] as $key => $value) {
                        edd_slm_add_log('- SLM Response ' . $key . ': ' . $value);
                    }
                    // Get license key
                    $license_key = edd_slm_get_license_key($response);
                    // Collect license keys
                    if ($license_key) {
                        $licenses[] = array('item' => $item_name, 'key' => $license_key);
                    }
                }
            }
        }
    }
    // Payment note
    edd_slm_payment_note($payment_id, $licenses);
    // Assign licenses
    edd_slm_assign_licenses($payment_id, $licenses);
}