/**
 * Check if the users purchase qualifies for a NOD offer.
 *
 * @param	int			$purchase_count		Purchase count of customer.
 * @return	bool		true if this the customer is eligible, false if not.
 *
 * @since 0.0.4
 * @return
 */
function wc_nod_purchase_qualifies($purchase_count)
{
    // First offer
    if ($purchase_count < WC_NOD()->settings->first) {
        return false;
    }
    if ($purchase_count == WC_NOD()->settings->first) {
        return true;
    }
    // Second offer
    if (empty(WC_NOD()->settings->repeat)) {
        return false;
    }
    if ($purchase_count == WC_NOD()->settings->repeat) {
        return true;
    }
    // Repeat offers
    if ($purchase_count % WC_NOD()->settings->repeat == 0 && get_option('nod_continue', false)) {
        return true;
    }
    return false;
}
/**
 * Add NOD registered settings to the WooCommerce extensions tab
 *
 * @since	    0.0.1
 * @global		
 * @param
 * @return
 */
function nod_registered_settings()
{
    return apply_filters('woo_nod_settings', array('nod_settings_title' => array('name' => __('General NOD Settings', 'wc-next-order-discount'), 'type' => 'title', 'desc' => '', 'id' => 'nod_settings_title'), 'nod_enable' => array('name' => __('Enable Next Order Discount?', 'wc-next-order-discount'), 'type' => 'checkbox', 'desc' => __('Check this box to enable the Next Order Discount feature.', 'wc-next-order-discount'), 'id' => 'nod_enable'), 'nod_first' => array('id' => 'nod_first', 'name' => __('First NOD after', 'edd-nod'), 'desc' => __('Enter the number of orders a customer must complete before qualifying for their first NOD.', 'edd-nod'), 'type' => 'number', 'class' => 'small-text', 'default' => WC_NOD()->settings->first), 'nod_continue' => array('id' => 'nod_continue', 'name' => __('Continue with NOD offers?', 'edd-nod'), 'desc' => sprintf(__('Check this box to send NOD offers after customer completes every %sRepeat NOD offer after every%s orders.', 'edd-nod'), '<code>', '</code>'), 'type' => 'checkbox'), 'nod_repeat' => array('id' => 'nod_repeat', 'name' => __('Repeat NOD offer after every', 'edd-nod'), 'desc' => __('Enter the number of orders the customer needs to complete to qualify for their second NOD. Enter 0 to deactivate.', 'edd-nod'), 'type' => 'number', 'class' => 'small-text', 'default' => WC_NOD()->settings->repeat), 'nod_free' => array('id' => 'nod_free', 'name' => __('Apply to Free Purchases?', 'wc-next-order-discount'), 'desc' => __('Check this box to enable the Next Order Discount following free purchases.', 'wc-next-order-discount'), 'type' => 'checkbox'), 'nod_min_spend' => array('id' => 'nod_min_spend', 'name' => __('Minimum Spend', 'wc-next-order-discount'), 'desc' => __('Enter the minimum spend required for Next Order Discount (i.e. 10), or leave empty.', 'wc-next-order-discount'), 'type' => 'number', 'class' => 'small-text', 'default' => WC_NOD()->settings->min_spend), 'nod_prefix' => array('id' => 'nod_prefix', 'name' => __('Discount Code Prefix', 'wc-next-order-discount'), 'desc' => __('Enter a prefix for the discount code, or leave empty.', 'wc-next-order-discount'), 'type' => 'text', 'default' => WC_NOD()->settings->prefix), 'nod_rate' => array('id' => 'nod_rate', 'name' => __('Discount Amount', 'wc-next-order-discount'), 'desc' => __('Enter the discount amount.', 'wc-next-order-discount'), 'type' => 'number', 'class' => 'small-text', 'default' => WC_NOD()->settings->rate), 'nod_type' => array('id' => 'nod_type', 'name' => __('Discount Type', 'wc-next-order-discount'), 'desc' => __('The kind of discount to apply for Next Order Discounts.', 'wc-next-order-discount'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array('fixed_cart' => __('Cart Discount', 'wc-next-order-discount'), 'percent' => __('Cart % Discount', 'wc-next-order-discount')), 'default' => WC_NOD()->settings->type), 'nod_send_after' => array('id' => 'nod_send_after', 'name' => __('Send Offer After', 'wc-next-order-discount'), 'desc' => __('Select length of time after purchase to wait before sending the offer.', 'wc-next-order-discount'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array('5 minutes' => __('5 Minutes (For Testing)', 'wc-next-order-discount'), '12 hours' => __('12 Hours', 'wc-next-order-discount'), '1 day' => __('1 Day', 'wc-next-order-discount'), '36 hours' => __('36 Hours', 'wc-next-order-discount'), '2 days' => __('2 Days', 'wc-next-order-discount'), '3 days' => __('3 Days', 'wc-next-order-discount'), '4 days' => __('4 Days', 'wc-next-order-discount'), '5 days' => __('5 Days', 'wc-next-order-discount'), '6 days' => __('6 Days', 'wc-next-order-discount'), '1 week' => __('1 Week', 'wc-next-order-discount')), 'default' => WC_NOD()->settings->send_after), 'nod_expires' => array('id' => 'nod_expires', 'name' => __('Offer Expires after', 'wc-next-order-discount'), 'desc' => __('Select time period offer is valid for.', 'wc-next-order-discount'), 'type' => 'select', 'class' => 'wc-enhanced-select', 'options' => array('1 day' => __('1 Day', 'wc-next-order-discount'), '2 days' => __('2 Days', 'wc-next-order-discount'), '3 days' => __('3 Days', 'wc-next-order-discount'), '4 days' => __('4 Days', 'wc-next-order-discount'), '5 days' => __('5 Days', 'wc-next-order-discount'), '6 days' => __('6 Days', 'wc-next-order-discount'), '1 week' => __('1 Week', 'wc-next-order-discount'), '10 days' => __('10 Days', 'wc-next-order-discount'), '2 weeks' => __('2 Weeks', 'wc-next-order-discount'), '1 month' => __('1 Month', 'wc-next-order-discount')), 'default' => WC_NOD()->settings->expires), array('type' => 'sectionend', 'id' => 'nod-main-end')));
}
Beispiel #3
0
function WC_NOD_Load()
{
    if (class_exists('WooCommerce')) {
        WC_NOD();
    }
}
 /**
  * Prepare the NOD email content.
  * 
  * @param	arr		$nod			Required: The NOD offer data
  * @param	int		$discount_id	Required: The NOD offer discount ID
  *
  * @return	arr		Array of prepared email data
  */
 public function prepare_email($nod, $discount_id, $email)
 {
     $type = WC_NOD()->settings->email_type;
     $to_email = $email->object->billing_email;
     $subject = apply_filters('nod_offer_subject', wp_strip_all_tags($email->get_subject()), $nod['order_id']);
     $subject = $email->format_string($subject);
     $subject = nod_do_email_tags($subject, $discount_id);
     $heading = WC_NOD()->settings->email_heading;
     $heading = $email->format_string($heading);
     $heading = nod_do_email_tags($heading, $discount_id);
     $heading = apply_filters('nod_offer_heading', $heading, $nod['order_id']);
     $attachments = apply_filters('nod_offer_attachments', $email->get_attachments(), $nod['order_id']);
     $message = $email->format_string($email->get_content());
     $message = nod_do_email_tags($message, $discount_id);
     $content = $email->get_email_header($heading, $type) . $message . $email->get_email_footer($type);
     return array('to_email' => $to_email, 'subject' => $subject, 'heading' => $heading, 'attachments' => $attachments, 'message' => $content);
 }
 /**
  * Create the unique NOD discount code.
  *
  * This function generates a new discount code to be used when creating the discount.
  * 
  * @params
  *
  * @return	str		The newly generated code
  */
 public function generate_code()
 {
     // Generate a new code using the defined prefix and random numbers/letters.
     $code = WC_NOD()->settings->prefix . substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, 4);
     return apply_filters('nod_generate_code', $code, WC_NOD()->settings->prefix);
 }
Beispiel #6
0
 /**
  * Initialise the NOD email settings options.
  *
  *
  * @since 0.0.1
  *
  */
 public function init_form_fields()
 {
     $this->form_fields = array('subject' => array('id' => 'subject', 'title' => __('Offer Email Subject', 'wc-next-order-discount'), 'description' => __('Enter the subject line for the NOD email.', 'wc-next-order-discount'), 'type' => 'text', 'placeholder' => '', 'default' => WC_NOD()->settings->email_subject), 'heading' => array('id' => 'heading', 'title' => __('Offer Email Heading', 'wc-next-order-discount'), 'description' => __('Enter the heading for the NOD email.', 'wc-next-order-discount'), 'type' => 'text', 'placeholder' => '', 'default' => WC_NOD()->settings->email_heading), 'email_type' => array('id' => 'email_type', 'title' => __('Email type', 'wc-next-order-discount'), 'type' => 'select', 'description' => __('Choose which format of email to send.', 'wc-next-order-discount'), 'default' => WC_NOD()->settings->email_type, 'class' => 'wc-enhanced-select', 'options' => array('plain' => __('Plain text', 'wc-next-order-discount'), 'html' => __('HTML', 'wc-next-order-discount'), 'multipart' => __('Multipart', 'wc-next-order-discount'))), 'admin_emails' => array('id' => 'admin_emails', 'title' => __('NOD Notification Emails', 'wc-next-order-discount'), 'description' => __('Enter the email address(es) that should receive a notification anytime a NOD offer is made, one per line.', 'wc-next-order-discount'), 'type' => 'textarea', 'css' => 'width:200px; height: 75px;', 'default' => WC_NOD()->settings->admin_emails), 'no_admin_emails' => array('id' => 'no_admin_emails', 'title' => __('Disable Admin Notifications', 'wc-next-order-discount'), 'description' => __('Check this box if you do not want NOD offers to be blind copied to admins. Will overide NOD Notification Emails.', 'wc-next-order-discount'), 'type' => 'checkbox', 'default' => WC_NOD()->settings->disable_admin));
 }