Example #1
0
 public function filter_reminder_template_tags($text = '', $license_id = 0)
 {
     $payment_id = get_post_meta($license_id, '_edd_sl_payment_id', true);
     $user_info = edd_get_payment_meta_user_info($payment_id);
     $user_id = edd_get_payment_user_id($payment_id);
     // Retrieve the customer name
     if ($user_id) {
         $user_data = get_userdata($user_id);
         $customer_name = $user_data->display_name;
     } elseif (isset($user_info['first_name'])) {
         $customer_name = $user_info['first_name'];
     } else {
         $customer_name = $user_info['email'];
     }
     $license_key = edd_software_licensing()->get_license_key($license_id);
     $download_id = get_post_meta($license_id, '_edd_sl_download_id', true);
     $product_name = get_the_title($download_id);
     $expiration = edd_software_licensing()->get_license_expiration($license_id);
     $expiration = date(get_option('date_format'), $expiration);
     $discount = edd_sl_get_renewal_discount_percentage($license_id);
     $renewal_link = apply_filters('edd_sl_renewal_link', edd_get_checkout_uri(array('edd_license_key' => $license_key, 'download_id' => $download_id)));
     $text = str_replace('{name}', $customer_name, $text);
     $text = str_replace('{license_key}', $license_key, $text);
     $text = str_replace('{product_name}', $product_name, $text);
     $text = str_replace('{expiration}', $expiration, $text);
     if (!empty($discount)) {
         $text = str_replace('{renewal_discount}', $discount . '%', $text);
     }
     $text = str_replace('{renewal_link}', $renewal_link, $text);
     return $text;
 }
Example #2
0
 public function fire_drip_expired_event($license_id = 0, $period = null)
 {
     // global $edd_options;
     if (empty($license_id) || empty($period) || !class_exists('edd_software_licensing')) {
         return;
     }
     //fetch the license
     $license = get_post($license_id);
     if (!$license || 'edd_license' != $license->post_type || !empty($license->post_parent)) {
         return;
     }
     //error_log(var_export($license,true));
     $customer = false;
     if (class_exists('EDD_Customer')) {
         $payment_id = get_post_meta($license->ID, '_edd_sl_payment_id', true);
         $customer_id = edd_get_payment_customer_id($payment_id);
         $customer = new EDD_Customer($customer_id);
     }
     //error_log(var_export($customer,true));
     //IF the customer ID is empty then use the payment to get the email info
     if (empty($customer->id)) {
         // Remove the post title to get just the email
         $title = $license->post_title;
         $title_pos = strpos($title, '-') + 1;
         $length = strlen($title);
         $email_to = substr($title, $title_pos, $length);
     }
     //Get the email.
     $customer_email = !empty($customer->id) ? $customer->email : $email_to;
     $customer_name = !empty($customer->id) ? $customer->name : null;
     //default to null
     //                $payment_id = get_post_meta( $license_id, '_edd_sl_payment_id', true );
     //                $user_info  = edd_get_payment_meta_user_info( $payment_id );
     //                $user_id    = edd_get_payment_user_id( $payment_id );
     //
     //                // Retrieve the customer name
     //                if ( $user_id ) {
     //                    $user_data     = get_userdata( $user_id );
     //                    $customer_name = $user_data->display_name;
     //                } elseif ( isset( $user_info['first_name'] ) ) {
     //                    $customer_name = $user_info['first_name'];
     //                } else {
     //                    $customer_name = $user_info['email'];
     //                }
     //These are custom fields on customer
     $license_key = edd_software_licensing()->get_license_key($license_id);
     $download_id = get_post_meta($license_id, '_edd_sl_download_id', true);
     $product_name = get_the_title($download_id);
     $expiration = edd_software_licensing()->get_license_expiration($license_id);
     $expiration = date(get_option('date_format'), $expiration);
     $discount_percent = edd_sl_get_renewal_discount_percentage($license_id);
     $renewal_link = apply_filters('edd_sl_renewal_link', edd_get_checkout_uri(array('edd_license_key' => $license_key, 'download_id' => $download_id)));
     //Fire the event
     error_log('FIRE DRIP EVENT:' . $period . '-' . $license_id);
     error_log($customer_name);
     error_log($license_key);
     error_log($product_name);
     error_log($expiration);
     error_log($discount_percent);
     error_log($renewal_link);
     return true;
     $text = str_replace('{name}', $customer_name, $text);
     $text = str_replace('{license_key}', $license_key, $text);
     $text = str_replace('{product_name}', $product_name, $text);
     $text = str_replace('{expiration}', $expiration, $text);
     if (!empty($discount)) {
         $text = str_replace('{renewal_discount}', $discount . '%', $text);
     }
     $text = str_replace('{renewal_link}', $renewal_link, $text);
     return $text;
     return false;
     //            $message    = $this->filter_reminder_template_tags( $message, $license_id );
     //
     //            $subject    = ! empty( $notice['subject'] ) ? $notice['subject'] : __( 'Your License Key is About to Expire', 'edd_sl' );
     //            $subject    = $this->filter_reminder_template_tags( $subject, $license_id );
     if ($sent) {
         $log_id = wp_insert_post(array('post_title' => __('LOG - Renewal Drip Event Fired', 'edd_sl'), 'post_name' => 'log-notice-sent-' . $license_id . '-' . md5(time()), 'post_type' => 'edd_license_log', 'post_status' => 'publish'));
         //'_edd_drip_sl_renewal_sent_
         add_post_meta($log_id, '_edd_sl_log_license_id', $license_id);
         add_post_meta($log_id, '_edd_sl_renewal_notice_id', (int) $notice_id);
         wp_set_object_terms($log_id, 'renewal_notice', 'edd_log_type', false);
         add_post_meta($license_id, sanitize_key('_edd_drip_sl_renewal_sent_' . $notice['send_period']), time());
         // Prevent renewal notices from being sent more than once
     }
 }
Example #3
0
/**
 * Displays the renewal discount row on the cart
 *
 * @since 3.0.2
 * @return void
 */
function edd_sl_cart_items_renewal_row()
{
    if (!edd_sl_renewals_allowed()) {
        return;
    }
    if (!EDD()->session->get('edd_is_renewal')) {
        return;
    }
    // bail early if a renewal discount is not set (or set at 0)
    $renewal_discount = edd_sl_get_renewal_discount_percentage();
    if (empty($renewal_discount)) {
        return;
    }
    $cart_items = edd_get_cart_content_details();
    $renewals = edd_sl_get_renewal_keys();
    $discount_amount = 0;
    foreach ($cart_items as $key => $item) {
        if (!isset($renewals[$key])) {
            continue;
        }
        $discount_amount += edd_sl_get_renewal_discount_amount($item, $renewals[$key]);
    }
    $discount_amount = edd_currency_filter(edd_format_amount($discount_amount));
    ?>
	<tr class="edd_cart_footer_row edd_sl_renewal_row">
		<td colspan="3"><?php 
    printf(__('License renewal discount: %s - %s', 'edd_sl'), $renewal_discount . '%', $discount_amount);
    ?>
</td>
	</tr>
<?php 
}