/**
 * Get boleto URL from order key.
 *
 * @param  int $order_id
 *
 * @return string
 */
function wc_boleto_get_boleto_url_by_order_id($order_id)
{
    $order_id = intval($order_id);
    $order = new WC_Order($order_id);
    if (isset($order->order_key)) {
        return wc_boleto_get_boleto_url($order->order_key);
    }
    return '';
}
 /**
  * Add content to the WC emails.
  *
  * @param  object $order         Order object.
  * @param  bool   $sent_to_admin Send to admin.
  *
  * @return string                Billet instructions.
  */
 function email_instructions($order, $sent_to_admin)
 {
     if ($sent_to_admin || 'on-hold' !== $order->status || 'boleto' !== $order->payment_method) {
         return;
     }
     $html = '<h2>' . __('Payment', 'woocommerce-boleto') . '</h2>';
     $html .= '<p class="order_details">';
     $message = sprintf(__('%sAttention!%s You will not get the ticket by Correios.', 'woocommerce-boleto'), '<strong>', '</strong>') . '<br />';
     $message .= __('Please click the following button and pay the Ticket in your Internet Banking.', 'woocommerce-boleto') . '<br />';
     $message .= __('If you prefer, print and pay at any bank branch or lottery retailer.', 'woocommerce-boleto') . '<br />';
     $html .= apply_filters('wcboleto_email_instructions', $message);
     $html .= '<br />' . sprintf('<a class="button" href="%s" target="_blank">%s</a>', esc_url(wc_boleto_get_boleto_url($order->order_key)), __('Pay the Ticket &rarr;', 'woocommerce-boleto')) . '<br />';
     $html .= '<strong style="font-size: 0.8em">' . sprintf(__('Validity of the Ticket: %s.', 'woocommerce-boleto'), date('d/m/Y', time() + absint($this->boleto_time) * 86400)) . '</strong>';
     $html .= '</p>';
     echo $html;
 }
 /**
  * Display pending payment message in order details.
  *
  * @param  int $order_id Order id.
  *
  * @return string        Message HTML.
  */
 public function pending_payment_message($order_id)
 {
     $order = new WC_Order($order_id);
     if ('on-hold' === $order->status && 'boleto' == $order->payment_method) {
         $html = '<div class="woocommerce-info">';
         $html .= sprintf('<a class="button" href="%s" target="_blank" style="display: block !important; visibility: visible !important;">%s</a>', esc_url(wc_boleto_get_boleto_url($order->order_key)), __('Pay the Ticket &rarr;', 'woocommerce-boleto'));
         $message = sprintf(__('%sAttention!%s Not registered the payment the docket for this product yet.', 'woocommerce-boleto'), '<strong>', '</strong>') . '<br />';
         $message .= __('Please click the following button and pay the Ticket in your Internet Banking.', 'woocommerce-boleto') . '<br />';
         $message .= __('If you prefer, print and pay at any bank branch or lottery retailer.', 'woocommerce-boleto') . '<br />';
         $message .= __('Ignore this message if the payment has already been made​​.', 'woocommerce-boleto') . '<br />';
         $html .= apply_filters('wcboleto_pending_payment_message', $message, $order);
         $html .= '</div>';
         echo $html;
     }
 }
 /**
  * New expiration date email notification.
  *
  * @param object $order           Order data.
  * @param string $expiration_date Ticket expiration date.
  */
 protected function email_notification($order, $expiration_date)
 {
     if (defined('WC_VERSION') && version_compare(WC_VERSION, '2.1', '>=')) {
         $mailer = WC()->mailer();
     } else {
         global $woocommerce;
         $mailer = $woocommerce->mailer();
     }
     $subject = sprintf(__('New expiration date for the boleto your order %s', 'woocommerce-boleto'), $order->get_order_number());
     // Mail headers.
     $headers = array();
     $headers[] = "Content-Type: text/html\r\n";
     // Body message.
     $main_message = '<p>' . sprintf(__('The expiration date of your boleto was updated to: %s', 'woocommerce-boleto'), '<code>' . $expiration_date . '</code>') . '</p>';
     $main_message .= '<p>' . sprintf('<a class="button" href="%s" target="_blank">%s</a>', esc_url(wc_boleto_get_boleto_url($order->order_key)), __('Pay the Ticket &rarr;', 'woocommerce-boleto')) . '</p>';
     // Sets message template.
     $message = $mailer->wrap_message(__('New expiration date for your boleto', 'woocommerce-boleto'), $main_message);
     // Send email.
     $mailer->send($order->billing_email, $subject, $message, $headers, '');
 }