Commit 10bb72f2 authored by Varun Sridharan's avatar Varun Sridharan

Bug Fix & Tweaks

* Fixed #49
* Fixed Email Template Call Issue (admin-new-donation)
* Fixed Few Donation Processing Issue
* Recreated admin new donation email
* Rarranged Class INI
* Added Versions For Email Template
parent f4b73b3e
......@@ -62,7 +62,7 @@ class WooCommerce_Quick_Donation_Emails_Functions {
}
public function check_order($order_id){
if(!WC_QD()->db()->_is_donation($order_id)){return;}
if(! WC_QD()->db()->_is_donation($order_id)){return;}
$this->remove_emails = true;
}
......
......@@ -45,7 +45,7 @@ class WooCommerce_Quick_Donation_Functions {
'emails/email-styles.php' => 'emails/donation-email-styles.php',
'emails/donation-customer-invoice.php' => 'emails/donation-customer-invoice.php',
'emails/donation-admin-new.php' => 'emails/donation-admin-new.php',
'emails/email-addresses.php' => 'emails/donation-email-addresses.php',
'emails/donation-email-footer.php' => 'emails/donation-email-footer.php',
'emails/donation-email-header.php' => 'emails/donation-email-header.php',
......
......@@ -11,6 +11,8 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
function __construct(){
parent::__construct();
add_action( 'woocommerce_checkout_update_order_meta',array($this,'save_order_id_db'),1);
add_action( 'wp_loaded',array($this,'on_wp_loaded'),20);
add_filter( 'woocommerce_get_price', array($this,'get_price'),10,2);
}
......@@ -19,9 +21,6 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
if($this->check_donation_exists_cart()){
$this->is_donation_exists = true;
add_action('woocommerce_add_order_item_meta',array($this,'add_order_meta'),99,3);
add_action( 'woocommerce_checkout_update_order_meta',array($this,'update_order_meta'));
add_action( 'woocommerce_checkout_update_order_meta', array($this,'save_order_id_db'));
//add_action( 'woocommerce_email',array($this,'remove_email_actions'));
add_filter( 'wc_quick_donation_cart_project_name', array($this,'change_donation_name'));
}
$this->process_donation();
......@@ -106,6 +105,7 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
$woocommerce->session->donation_price = $donate_price;
$woocommerce->session->projects = $projects;
$woocommerce->session->is_donation_product = true;
$donation_added = $woocommerce->cart->add_to_cart(self::$donation_id);
......@@ -199,12 +199,6 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
}
}
public function update_order_meta($order_id){
global $woocommerce;
update_post_meta( $order_id,"_is_donation",true);
update_post_meta( $order_id,"_project_details",$woocommerce->session->projects);
}
public function add_order_meta($item_id, $values, $cart_item_key){
global $woocommerce;
......@@ -215,10 +209,14 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
public function save_order_id_db($order_id){
global $woocommerce;
if($this->check_donation_exists_cart()){
$project_id = intval($woocommerce->session->projects);
$user_id = get_current_user_id();
update_post_meta( $order_id,"_is_donation",true);
update_post_meta( $order_id,"_project_details",$woocommerce->session->projects);
WC_QD()->db()->add_db_option($order_id,$project_id,$user_id);
}
}
public function get_checkout_project_id(){
......@@ -235,7 +233,6 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
*/
public function get_price($price, $product){
global $woocommerce;
if($product->id == self::$donation_id){
return isset($woocommerce->session->donation_price) ? floatval($woocommerce->session->donation_price) : 0;
}
......@@ -245,4 +242,4 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
}
?>
\ No newline at end of file
?>
\ No newline at end of file
......@@ -7,68 +7,57 @@ if ( ! defined( 'ABSPATH' ) ) {
if ( ! class_exists( 'WC_QD_Donation_New_Email' ) ) :
/**
* Customer Invoice
* New Order Email
*
* An email sent to the customer via admin.
* An email sent to the admin when a new order is received/paid for.
*
* @class WC_QD_Donation_New_Email
* @version 2.3.0
* @version 2.0.0
* @package WooCommerce/Classes/Emails
* @author WooThemes
* @extends WC_Email
*/
class WC_QD_Donation_New_Email extends WC_Email {
public $find;
public $replace;
/**
* Constructor
*/
function __construct() {
$this->id = WC_QD_DB.'donation_new_email';
$this->title = __( 'New Donation', 'woocommerce' );
$this->description = __( 'Customer invoice emails can be sent to customers containing their order information and payment links.', 'woocommerce' );
$this->title = __( 'New Donation ', WC_QD_TXT );
$this->description = __( 'New order emails are sent to the recipient list when an order is received. you can use <code> {project_name} </code> to get project name any where in the below fields', WC_QD_TXT );
$this->template_base = WC_QD_TEMPLATE;
$this->template_html = 'emails/donation-customer-invoice.php';
$this->template_plain = 'emails/plain/donation-customer-invoice.php';
$this->heading = __( 'New customer donation for {project_name}', WC_QD_TXT );
$this->subject = __( '[{site_title}] New customer donation ({order_number}) - {order_date}', WC_QD_TXT );
$this->subject = __( 'Reg : Your Recent Donation @ {site_title}', WC_QD_TXT);
$this->heading = __( 'Thank you. Your Donation has been received for {project_name}', 'woocommerce');
$this->template_base = WC_QD_TEMPLATE;
$this->template_html = 'emails/donation-admin-new.php';
$this->template_plain = 'emails/plain/admin-new-order.php';
$this->subject_paid = __( 'Your {site_title} order from {order_date}', 'woocommerce');
$this->heading_paid = __( 'Order {order_number} details', 'woocommerce');
add_filter('woocommerce_template_directory',array($this,'change_dir'),2,1);
// Call parent constructor
parent::__construct();
$this->heading_paid = $this->get_option( 'heading_paid', $this->heading_paid );
$this->subject_paid = $this->get_option( 'subject_paid', $this->subject_paid );
// Other settings
$this->recipient = $this->get_option( 'recipient' );
add_filter('woocommerce_template_directory',array($this,'change_dir'),2,1);
if ( ! $this->recipient )
$this->recipient = get_option( 'admin_email' );
}
public function change_dir($dir){
$dir = $dir.'/donation';
return $dir;
}
/**
* Trigger.
*/
function trigger( $order ) {
if ( ! is_object( $order ) ) {
$order = wc_get_order( absint( $order ) );
}
function trigger( $order_id ) {
if ( $order ) {
$this->object = $order;
$this->recipient = $this->object->billing_email;
if ( $order_id ) {
$this->object = wc_get_order( $order_id );
$this->find['order-date'] = '{order_date}';
$this->find['order-number'] = '{order_number}';
......@@ -78,47 +67,19 @@ class WC_QD_Donation_New_Email extends WC_Email {
$project_id = WC_QD()->db()->get_project_id($order_id);
$project_name = get_the_title($project_id);
$this->replace['order-date'] = date_i18n( wc_date_format(), strtotime( $this->object->order_date ) );
$this->replace['order-number'] = $this->object->get_order_number();
$this->replace['donation-project-name'] = $project_name;
}
if ( ! $this->get_recipient() ) {
if ( ! $this->is_enabled() || ! $this->get_recipient() ) {
return;
}
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
/**
* get_subject function.
*
* @access public
* @return string
*/
function get_subject() {
if ( $this->object->has_status( array( 'processing', 'completed' ) ) ) {
return $this->format_string( $this->subject_paid );
} else {
return $this->format_string( $this->subject );
}
}
/**
* get_heading function.
*
* @access public
* @return string
*/
function get_heading() {
if ( $this->object->has_status( array( 'completed', 'processing' ) ) ) {
return $this->format_string( $this->heading_paid );
} else {
return $this->format_string( $this->heading );
}
}
/**
* get_content_html function.
*
......@@ -130,7 +91,7 @@ class WC_QD_Donation_New_Email extends WC_Email {
wc_get_template( $this->template_html, array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'sent_to_admin' => true,
'plain_text' => false
) );
return ob_get_clean();
......@@ -147,12 +108,10 @@ class WC_QD_Donation_New_Email extends WC_Email {
wc_get_template( $this->template_plain, array(
'order' => $this->object,
'email_heading' => $this->get_heading(),
'sent_to_admin' => false,
'sent_to_admin' => true,
'plain_text' => true
) );
return ob_get_clean();
}
/**
......@@ -160,46 +119,43 @@ class WC_QD_Donation_New_Email extends WC_Email {
*/
function init_form_fields() {
$this->form_fields = array(
'subject' => array(
'title' => __( 'Email Subject', 'woocommerce' ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject ),
'placeholder' => '',
'default' => ''
'enabled' => array(
'title' => __( 'Enable/Disable', WC_QD_TXT ),
'type' => 'checkbox',
'label' => __( 'Enable this email notification', WC_QD_TXT ),
'default' => 'yes'
),
'heading' => array(
'title' => __( 'Email Heading', 'woocommerce' ),
'recipient' => array(
'title' => __( 'Recipient(s)', WC_QD_TXT ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading ),
'description' => sprintf( __( 'Enter recipients (comma separated) for this email. Defaults to <code>%s</code>.', WC_QD_TXT ), esc_attr( get_option('admin_email') ) ),
'placeholder' => '',
'default' => ''
),
'subject_paid' => array(
'title' => __( 'Email Subject (paid)', 'woocommerce' ),
'subject' => array(
'title' => __( 'Subject', WC_QD_TXT ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->subject_paid ),
'description' => sprintf( __( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', WC_QD_TXT ), $this->subject ),
'placeholder' => '',
'default' => ''
),
'heading_paid' => array(
'title' => __( 'Email Heading (paid)', 'woocommerce' ),
'heading' => array(
'title' => __( 'Email Heading', WC_QD_TXT ),
'type' => 'text',
'description' => sprintf( __( 'Defaults to <code>%s</code>', 'woocommerce' ), $this->heading_paid ),
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.', WC_QD_TXT ), $this->heading ),
'placeholder' => '',
'default' => ''
),
'email_type' => array(
'title' => __( 'Email Type', 'woocommerce' ),
'title' => __( 'Email type', WC_QD_TXT ),
'type' => 'select',
'description' => __( 'Choose which format of email to send.', 'woocommerce' ),
'description' => __( 'Choose which format of email to send.', WC_QD_TXT ),
'default' => 'html',
'class' => 'email_type wc-enhanced-select',
'options' => $this->get_email_type_options()
)
);
}
}
endif;
......
No preview for this file type
This diff is collapsed.
<?php
/**
* Customer invoice email
*
* @author Varun Sridharan
* @package WooCommerce Quick Donation/Templates/emails
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
?>
<?php do_action( 'woocommerce_donation_email_header', $email_heading ); ?>
<?php if ( $order->has_status( 'pending' ) ) : ?>
<p><?php printf( __( 'An order has been created for you on %s. To pay for this order please use the following link: %s', 'woocommerce' ), get_bloginfo( 'name', 'display' ), '<a href="' . esc_url( $order->get_checkout_payment_url() ) . '">' . __( 'pay', 'woocommerce' ) . '</a>' ); ?></p>
<?php endif; ?>
<?php do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text ); ?>
<h2><?php printf( __( 'Donation ID #%s', 'woocommerce' ), $order->get_order_number() ); ?> (<?php printf( '<time datetime="%s">%s</time>', date_i18n( 'c', strtotime( $order->order_date ) ), date_i18n( wc_date_format(), strtotime( $order->order_date ) ) ); ?>)</h2>
<table class="td" cellspacing="0" cellpadding="6" style="width: 100%; font-family: 'Helvetica Neue', Helvetica, Roboto, Arial, sans-serif;" border="1">
<thead>
<tr>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Project', WC_QD_TXT ); ?></th>
<th class="td" scope="col" style="text-align:left;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php
switch ( $order->get_status() ) {
case "completed" :
echo $order->email_order_items_table( false, false, true );
break;
case "processing" :
echo $order->email_order_items_table( false, true, true );
break;
default :
echo $order->email_order_items_table( false, true, false );
break;
}
?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $subKey => $total ) {
$i++;
if($subKey == 'cart_subtotal' || $subKey == 'order_total'){continue;}
?><tr>
<td class="td" colspan="1" style="text-align:left; <?php if ( $i == 1 ) echo 'border-top-width: 4px !important;'; ?>"><?php echo $total['label']; ?></td>
<td class="td" style="text-align:left; <?php if ( $i == 1 ) echo 'border-top-width: 4px !important;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text ); ?>
<?php do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text ); ?>
<?php do_action( 'woocommerce_donation_email_footer' ); ?>
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.1.2
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.3.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails
* @version 2.4.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
<?php
/**
* Customer invoice email (plain text)
*
* @author Varun Sridharan
* @package WooCommerce Quick Donation/Templates/emails/plain
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
echo "= " . $email_heading . " =\n\n";
if ( $order->has_status( 'pending' ) )
echo sprintf( __( 'An order has been created for you on %s. To pay for this order please use the following link: %s', 'woocommerce' ), get_bloginfo( 'name', 'display' ), $order->get_checkout_payment_url() ) . "\n\n";
echo "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text );
echo strtoupper( sprintf( __( 'Order number: %s', 'woocommerce' ), $order->get_order_number() ) ) . "\n";
echo date_i18n( __( 'jS F Y', 'woocommerce' ), strtotime( $order->order_date ) ) . "\n";
do_action( 'woocommerce_email_order_meta', $order, $sent_to_admin, $plain_text );
echo "\n";
switch ( $order->get_status() ) {
case "completed" :
echo $order->email_order_items_table( $order->is_download_permitted(), false, true, '', '', true );
break;
case "processing" :
echo $order->email_order_items_table( $order->is_download_permitted(), true, true, '', '', true );
break;
default :
echo $order->email_order_items_table( $order->is_download_permitted(), true, false, '', '', true );
break;
}
echo "==========\n\n";
if ( $totals = $order->get_order_item_totals() ) {
foreach ( $totals as $total ) {
echo $total['label'] . "\t " . $total['value'] . "\n";
}
}
echo "\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n\n";
do_action( 'woocommerce_email_after_order_table', $order, $sent_to_admin, $plain_text );
echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain
* @version 2.3.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain
* @version 2.2.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain
* @version 2.1.2
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -4,7 +4,7 @@
*
* @author WooThemes
* @package WooCommerce/Templates/Emails/Plain
* @version 2.3.0
* @version 0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
......
......@@ -130,10 +130,10 @@ class WooCommerce_Quick_Donation {
* Inits loaded Class
*/
private function init_class(){
self::$email = new WooCommerce_Quick_Donation_Emails_Functions;
self::$db = new WooCommerce_Quick_Donation_DB;
self::$f = new WooCommerce_Quick_Donation_Functions;
self::$settings = new WooCommerce_Quick_Donation_Settings;
self::$db = new WooCommerce_Quick_Donation_DB;
self::$email = new WooCommerce_Quick_Donation_Emails_Functions;
if($this->is_request('frontend')){
self::$shortcode = new WooCommerce_Quick_Donation_Shortcode;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment