/**
     * Trigger a notification
     * 
     * @access public
     * @param object $order
     * @param array $args
     * @param bool $send_to_admin
     * @return void
     */
    public function trigger($order, $args = array(), $send_to_admin = false)
    {
        if (!$order) {
            return;
        }

        $this->object = $order;

        if ($send_to_admin) {
            $this->recipient = get_option('admin_email');
        }
        else {
            $this->recipient = $this->object->billing_email;
        }

        // Replace macros
        $this->find[] = '{order_date}';
        $this->replace[] = date_i18n(wc_date_format(), strtotime($this->object->order_date));

        // Check if this email type is enabled, recipient is set and we are not on a development website
        if (!$this->is_enabled() || !$this->get_recipient() || !Subscriptio::is_main_site()) {
            return;
        }

        // Get subscription
        $subscription = Subscriptio_Order_Handler::get_subscriptions_from_order_id($order->id);
        $subscription = reset($subscription);

        if (!$subscription) {
            return;
        }

        $this->template_variables = array(
            'subscription'  => $subscription,
            'order'         => $this->object,
            'email_heading' => $this->get_heading(),
            'sent_to_admin' => false,
        );

        $this->send($this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments());
    }
 /**
  * Check if order is renewal order
  * 
  * @access public
  * @param bool $is_renewal
  * @param object $order
  * @return bool
  */
 public function is_renewal_order($is_renewal, $order)
 {
     return Subscriptio_Order_Handler::order_is_renewal($order->id);
 }
    /**
     * Scheduled renewal order event handler
     * 
     * @access public
     * @param int $subscription_id
     * @return void
     */
    public static function scheduled_order($subscription_id)
    {
        // Start transaction
        $transaction = new Subscriptio_Transaction(null, 'renewal_order');

        // Load subscription if it's still valid
        $subscription = Subscriptio_Subscription::get_valid_subscription($subscription_id, $transaction);

        // Got a valid subscription object?
        if (!$subscription) {
            return;
        }

        // Create renewal order
        try {
            $order_id = Subscriptio_Order_Handler::create_renewal_order($subscription);
            $transaction->add_order_id($order_id);
            $transaction->update_result('success');
            $transaction->update_note(__('New order created, status set to pending.', 'subscriptio'), true);
        } catch (Exception $e) {
            $transaction->update_result('error');
            $transaction->update_note($e->getMessage(), true);
        }
    }
Esempio n. 4
0
    /**
     * Display related subscriptions on single order view page
     * 
     * @access public
     * @param object $order
     * @return void
     */
    public function display_frontend_order_related_subscriptions($order)
    {
        $subscriptions = Subscriptio_Order_Handler::get_subscriptions_from_order_id($order->id);

        if (!empty($subscriptions) && apply_filters('subscriptio_display_order_related_subscriptions', true)) {
            Subscriptio::include_template('myaccount/subscription-list', array(
                'subscriptions' => $subscriptions,
                'title'         => __('Related Subscriptions', 'subscriptio'),
            ));
        }
    }
Esempio n. 5
0
    /**
     * Send custom Subscriptio email
     * 
     * @access public
     * @param int $order_id
     * @return void
     */
    public function send_custom_email($order_id)
    {
        $order = new WC_Order($order_id);

        if (!$order) {
            return;
        }

        // Subscription order?
        if (Subscriptio_Order_Handler::order_is_renewal($order_id)) {
            Subscriptio_Mailer::send($this->get_woocommerce_email_type(current_filter()), $order);
        }
    }