Commit 0e2b0fab authored by Tech No Freaky's avatar Tech No Freaky

0.2

Redirect User After Donation Added To Cart [Cart Page / Checkout Page]
Select Your Preferred Payment Gateway For Donation
Custom Email Template For Donation Processing
Custom Email Template For Donation Completed
Some Minor Bug Fix
parent 4993e957
...@@ -4,7 +4,7 @@ Donate link: http://varunsridharan.in ...@@ -4,7 +4,7 @@ Donate link: http://varunsridharan.in
Tags: Woocommerce,Quick Dontion,Donation,Online Payment,Payment,Online,Donate,Monthly Goal Tags: Woocommerce,Quick Dontion,Donation,Online Payment,Payment,Online,Donate,Monthly Goal
Requires at least: 3.0 plus WooCommerce 2.x or higher Requires at least: 3.0 plus WooCommerce 2.x or higher
Tested up to: 4.0.1 + WooCommerce 2.x Tested up to: 4.0.1 + WooCommerce 2.x
Stable tag: 0.1 Stable tag: 0.2
License: GPLv2 or later License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html License URI: http://www.gnu.org/licenses/gpl-2.0.html
...@@ -12,19 +12,44 @@ Online Donation Using Woocoomerce. for woocommerce user's ...@@ -12,19 +12,44 @@ Online Donation Using Woocoomerce. for woocommerce user's
== Description == == Description ==
<h3> <blink> What's New In 0.2 </blink></h3>
* Redirect User After Donation Added To Cart [Cart Page / Checkout Page]
* Select Your Preferred Payment Gateway For Donation
* Custom Email Template For Donation Processing
* Custom Email Template For Donation Completed
* Some Minor Bug Fix
<h3> What We Will Give In Up Coming Releases </h3>
* Customized Report Page [Need Help]
* Better Email Template
* Target / Goal For The Project
WooCommerce Shopping Cart Donation which makes woocoomerce to use for online donation purpose. WooCommerce Shopping Cart Donation which makes woocoomerce to use for online donation purpose.
This plugin will create a new product in the name of *donation*. This plugin will create a new product in the name of **donation**.
This Plugin Can called by using the below shortcode This Plugin Can called by using the below short code
`[wc_quick_donation]` `[wc_quick_donation]`
This Plugin Template Can Be Found Under [You Can Modify The Template Buy Copying To Your Theme's Folder] **Plugin Template List** *[You Can Modify The Template Buy Copying To Your Theme's Folder]*
1. Donation Form Template
`wc-quick-donation/template/donation_form.php` `wc-quick-donation/template/donation_form.php`
2. Donation Processing Email Template
`wc-quick-donation/template/donation_processing_html.php`
`wc-quick-donation/template/donation_processing_plain.php`
3. Donation Completed Email Template
`wc-quick-donation/template/donation_completed_html.php`
`wc-quick-donation/template/donation_completed_plain.php`
Plugin Settings : ***Woocoomerce Settings => Quick Donation***
This Plugin Settings Can Be Found Under Email Template Settings : ***Woocommerce Settings => Emails => Donation Processing & Completed***
`Woocoomerce Settings => Quick Donation`
== Upgrade Notice ==
We have updated ***donation-form.php*** template. so please replace the template if you have modified
== Installation == == Installation ==
...@@ -48,17 +73,32 @@ This Plugin Can Be Called Using `[wc_quick_donation]` ...@@ -48,17 +73,32 @@ This Plugin Can Be Called Using `[wc_quick_donation]`
Yes. Its Possible By Copying To Your Theme's Folder `wp-content/plugins/wc-quick-donation/template/donation_form.php` Yes. Its Possible By Copying To Your Theme's Folder `wp-content/plugins/wc-quick-donation/template/donation_form.php`
**What Is The Use Of Project Field ?** **What Is The Use Of Project Field ?**
Project is like [category / division]. for which you donation. muiltiple can be entered by `,` seperated eg : `Project 1,Project 2` Project is like [category / division]. for which you donation. multiple can be entered by `,` separated eg : `Project 1,Project 2`
**Donation Plugin Not Working After Upgrading To 0.2**
As we have updated ***donation-form.php*** template. it may not be working with the old one. so please replace the template if you have modified or contact us.
**How i can get project name in email template**
You can get the name by calling the variable `$project_name`
**I have an idea for your plugin!** **I have an idea for your plugin!**
That\\'s great. We are always open to your input, and we would like to add anything we think will be useful to a lot of people. Please send your comment/idea to varunsridharan23@gmail.com That's great. We are always open to your input, and we would like to add anything we think will be useful to a lot of people. Please send your comment/idea to varunsridharan23@gmail.com
**I found a bug!** **I found a bug!**
Oops. Please User github / WordPress to post bugs. <a href="https://github.com/technofreaky/woocomerce-quick-donation/"> Open an Issue </a> Oops. Please User github / WordPress to post bugs. <a href="https://github.com/technofreaky/woocomerce-quick-donation/"> Open an Issue </a>
== Screenshots == == Screenshots ==
1. Settings Panel 1. Settings Panel
2. Email Template Settings For Donation Processing
3. Email Template Settings For Donation Completed.
== Changelog == == Changelog ==
= 0.2 =
* Redirect User After Donation Added To Cart [Cart Page / Checkout Page]
* Select Your Preferred Payment Gateway For Donation
* Custom Email Template For Donation Processing
* Custom Email Template For Donation Completed
* Some Minor Bug Fix
= 0.1 = = 0.1 =
* Base Version * Base Version
\ No newline at end of file
screenshot-1.png

55.9 KB | W: | H:

screenshot-1.png

53 KB | W: | H:

screenshot-1.png
screenshot-1.png
screenshot-1.png
screenshot-1.png
  • 2-up
  • Swipe
  • Onion skin
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>
<?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<p><?php printf( __( 'Thanks For Your Donation %s. Their order is as follows:', 'woocommerce' ), $order->billing_first_name . ' ' . $order->billing_last_name ); ?></p>
<?php do_action( 'woocommerce_email_before_order_table', $order, true, false ); ?>
<h2><a href="<?php echo admin_url( 'post.php?post=' . $order->id . '&action=edit' ); ?>"><?php printf( __( 'Order: %s', 'woocommerce'), $order->get_order_number() ); ?></a> <?php echo $project_name; ?> (<?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 cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
<thead>
<tr>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( false, true ); ?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, true, false ); ?>
<?php do_action( 'woocommerce_email_order_meta', $order, true, false ); ?>
<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
<?php if ( $order->billing_email ) : ?>
<p><strong><?php _e( 'Email:', 'woocommerce' ); ?></strong> <?php echo $order->billing_email; ?></p>
<?php endif; ?>
<?php if ( $order->billing_phone ) : ?>
<p><strong><?php _e( 'Tel:', 'woocommerce' ); ?></strong> <?php echo $order->billing_phone; ?></p>
<?php endif; ?>
<?php wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) ); ?>
<?php do_action( 'woocommerce_email_footer' ); ?>
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
echo $email_heading . "\n\n";
echo sprintf( __( 'You have received an order from %s. Their order is as follows:', 'woocommerce' ), $order->billing_first_name . ' ' . $order->billing_last_name ) . "\n\n";
echo "****************************************************\n\n";
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text );
echo sprintf( __( 'Order number: %s', 'woocommerce'), $order->get_order_number() ) . "\n";
echo sprintf( __( 'Order link: %s', 'woocommerce'), admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) . "\n";
echo sprintf( __( 'Order date: %s', 'woocommerce'), 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" . $order->email_order_items_table( false, true, '', '', '', true );
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 __( 'Customer details', 'woocommerce' ) . "\n";
if ( $order->billing_email )
echo __( 'Email:', 'woocommerce' ); echo $order->billing_email . "\n";
if ( $order->billing_phone )
echo __( 'Tel:', 'woocommerce' ); ?> <?php echo $order->billing_phone . "\n";
wc_get_template( 'emails/plain/email-addresses.php', array( 'order' => $order ) );
echo "\n****************************************************\n\n";
echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );
\ No newline at end of file
...@@ -22,10 +22,10 @@ global $donate; ...@@ -22,10 +22,10 @@ global $donate;
<div class="input text"> <div class="input text">
<label>Donation (&pound;):</label> <label>Donation (&pound;):</label>
<input type="text" name="jc-donation" value="<?php echo $donate; ?>"/> <input type="text" name="donation_ammount" value="<?php echo $donate; ?>"/>
</div> </div>
<div class="submit_btn"> <div class="submit_btn">
<input type="submit" name="donate-btn" value="Add Donation"/> <input type="submit" name="donation_add" value="Add Donation"/>
</div> </div>
</div> </div>
</td> </td>
......
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly ?>
<?php do_action( 'woocommerce_email_header', $email_heading ); ?>
<p><?php printf( __( 'Thanks For Your Donation %s. Their order is as follows:', 'woocommerce' ), $order->billing_first_name . ' ' . $order->billing_last_name ); ?></p>
<?php do_action( 'woocommerce_email_before_order_table', $order, true, false ); ?>
<h2><a href="<?php echo admin_url( 'post.php?post=' . $order->id . '&action=edit' ); ?>"><?php printf( __( 'Order: %s', 'woocommerce'), $order->get_order_number() ); ?></a> <?php echo $project_name; ?> (<?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 cellspacing="0" cellpadding="6" style="width: 100%; border: 1px solid #eee;" border="1" bordercolor="#eee">
<thead>
<tr>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Quantity', 'woocommerce' ); ?></th>
<th scope="col" style="text-align:left; border: 1px solid #eee;"><?php _e( 'Price', 'woocommerce' ); ?></th>
</tr>
</thead>
<tbody>
<?php echo $order->email_order_items_table( false, true ); ?>
</tbody>
<tfoot>
<?php
if ( $totals = $order->get_order_item_totals() ) {
$i = 0;
foreach ( $totals as $total ) {
$i++;
?><tr>
<th scope="row" colspan="2" style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['label']; ?></th>
<td style="text-align:left; border: 1px solid #eee; <?php if ( $i == 1 ) echo 'border-top-width: 4px;'; ?>"><?php echo $total['value']; ?></td>
</tr><?php
}
}
?>
</tfoot>
</table>
<?php do_action( 'woocommerce_email_after_order_table', $order, true, false ); ?>
<?php do_action( 'woocommerce_email_order_meta', $order, true, false ); ?>
<h2><?php _e( 'Customer details', 'woocommerce' ); ?></h2>
<?php if ( $order->billing_email ) : ?>
<p><strong><?php _e( 'Email:', 'woocommerce' ); ?></strong> <?php echo $order->billing_email; ?></p>
<?php endif; ?>
<?php if ( $order->billing_phone ) : ?>
<p><strong><?php _e( 'Tel:', 'woocommerce' ); ?></strong> <?php echo $order->billing_phone; ?></p>
<?php endif; ?>
<?php wc_get_template( 'emails/email-addresses.php', array( 'order' => $order ) ); ?>
<?php do_action( 'woocommerce_email_footer' ); ?>
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
echo $email_heading . "\n\n";
echo sprintf( __( 'You have received an order from %s. Their order is as follows:', 'woocommerce' ), $order->billing_first_name . ' ' . $order->billing_last_name ) . "\n\n";
echo "****************************************************\n\n";
do_action( 'woocommerce_email_before_order_table', $order, $sent_to_admin, $plain_text );
echo sprintf( __( 'Order number: %s', 'woocommerce'), $order->get_order_number() ) . "\n";
echo sprintf( __( 'Order link: %s', 'woocommerce'), admin_url( 'post.php?post=' . $order->id . '&action=edit' ) ) . "\n";
echo sprintf( __( 'Order date: %s', 'woocommerce'), 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" . $order->email_order_items_table( false, true, '', '', '', true );
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 __( 'Customer details', 'woocommerce' ) . "\n";
if ( $order->billing_email )
echo __( 'Email:', 'woocommerce' ); echo $order->billing_email . "\n";
if ( $order->billing_phone )
echo __( 'Tel:', 'woocommerce' ); ?> <?php echo $order->billing_phone . "\n";
wc_get_template( 'emails/plain/email-addresses.php', array( 'order' => $order ) );
echo "\n****************************************************\n\n";
echo apply_filters( 'woocommerce_email_footer_text', get_option( 'woocommerce_email_footer_text' ) );
\ No newline at end of file
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* A custom Expedited Order WooCommerce Email class
*
* @since 0.1
* @extends \WC_Email
*/
class wc_quick_donation_completed_donation_email extends WC_Email {
/**
* Set email defaults
*
* @since 0.1
*/
public function __construct() {
$this->project_name = '';
$this->id = 'wc_quick_donation_completed_donation_email';
$this->title = 'Donation completed';
$this->description = 'Email Sent When New Donation Is Placed';
$this->subject = 'Thank you for your donation {project_name}';
$this->heading = 'Thank you for your donation {project_name}';
$this->template_base = wc_qd_p.'template/';
$this->template_html = 'donation_completed_html.php';
$this->template_plain = 'donation_completed_plain.php';
// Trigger on new paid orders
add_action( 'woocommerce_order_status_completed_notification', array( $this, 'trigger' ) );
parent::__construct();
}
/**
* Determine if the email should actually be sent and setup email merge variables
*
* @since 0.1
* @param int $order_id
*/
public function trigger( $order_id ) {
if ( ! $order_id )
return;
$this->project_name = get_post_meta($order_id, 'project_details', true );
$order = new WC_Order( $order_id );
$this->object = $order;
$this->recipient = $this->object->billing_email;
$products_in_order = array();
foreach ( $order->get_items() as $item ) {
foreach($item['item_meta']['_product_id'] as $id){ $products_in_order[] = $id; }
}
if(in_array(get_option('wc_quick_donation_product_id'),$products_in_order)){
$this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{project_name}';
$this->replace[] = get_post_meta($order_id, 'project_details', true );
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number();
if ( ! $this->is_enabled())
return;
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
}
/**
* Initialize Settings Form Fields
*
* @since 0.1
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable this email notification',
'default' => 'yes'
),
'subject' => array(
'title' => 'Subject',
'type' => 'text',
'description' => sprintf( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', $this->subject ),
'placeholder' => '',
'default' => ''
),
'heading' => array(
'title' => 'Email Heading',
'type' => 'text',
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.' ), $this->heading ),
'placeholder' => '',
'default' => ''
),
'email_type' => array(
'title' => 'Email type',
'type' => 'select',
'description' => 'Choose which format of email to send.',
'default' => 'html',
'class' => 'email_type',
'options' => array(
'plain' => 'Plain text',
'html' => 'HTML',
'multipart' => 'Multipart'
)
)
);
}
/**
* get_content_html function.
*
* @since 0.1
* @return string
*/
public function get_content_html() {
ob_start();
woocommerce_get_template($this->template_html,array('project_name'=>$this->project_name,'order' => $this->object, 'email_heading' => $this->get_heading()),'',$this->template_base);
return ob_get_clean();
}
/**
* get_content_plain function.
*
* @since 0.1
* @return string
*/
public function get_content_plain() {
ob_start();
woocommerce_get_template($this->template_plain,array('project_name'=>$this->project_name,'order' => $this->object, 'email_heading' => $this->get_heading()),'',$this->template_base);
return ob_get_clean();
}
}
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* A custom Expedited Order WooCommerce Email class
*
* @since 0.1
* @extends \WC_Email
*/
class wc_quick_donation_processing_donation_email extends WC_Email {
/**
* Set email defaults
*
* @since 0.1
*/
public function __construct() {
$this->project_name = '';
$this->id = 'wc_quick_donation_processing_donation_email_processing';
$this->title = 'Donation Processing';
$this->description = 'Email Sent When New Donation Is Placed';
$this->subject = 'Thank you for your donation {project_name}';
$this->heading = 'Thank you for your donation {project_name}';
$this->template_base = wc_qd_p.'template/';
$this->template_html = 'donation_processing_html.php';
$this->template_plain = 'donation_processing_plain.php';
// Trigger on new paid orders
add_action( 'woocommerce_order_status_pending_to_processing_notification', array( $this, 'trigger' ) );
add_action( 'woocommerce_order_status_pending_to_on-hold_notification', array( $this, 'trigger' ) );
parent::__construct();
}
/**
* Determine if the email should actually be sent and setup email merge variables
*
* @since 0.1
* @param int $order_id
*/
public function trigger( $order_id ) {
if ( ! $order_id )
return;
$this->project_name = get_post_meta($order_id, 'project_details', true );
$order = new WC_Order( $order_id );
$this->object = $order;
$this->recipient = $this->object->billing_email;
$products_in_order = array();
foreach ( $order->get_items() as $item ) {
foreach($item['item_meta']['_product_id'] as $id){ $products_in_order[] = $id; }
}
if(in_array(get_option('wc_quick_donation_product_id'),$products_in_order)){
$this->find[] = '{order_date}';
$this->replace[] = date_i18n( woocommerce_date_format(), strtotime( $this->object->order_date ) );
$this->find[] = '{project_name}';
$this->replace[] = $this->project;
$this->find[] = '{order_number}';
$this->replace[] = $this->object->get_order_number();
if ( ! $this->is_enabled())
return;
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
}
}
/**
* Initialize Settings Form Fields
*
* @since 0.1
*/
public function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable this email notification',
'default' => 'yes'
),
'subject' => array(
'title' => 'Subject',
'type' => 'text',
'description' => sprintf( 'This controls the email subject line. Leave blank to use the default subject: <code>%s</code>.', $this->subject ),
'placeholder' => '',
'default' => ''
),
'heading' => array(
'title' => 'Email Heading',
'type' => 'text',
'description' => sprintf( __( 'This controls the main heading contained within the email notification. Leave blank to use the default heading: <code>%s</code>.' ), $this->heading ),
'placeholder' => '',
'default' => ''
),
'email_type' => array(
'title' => 'Email type',
'type' => 'select',
'description' => 'Choose which format of email to send.',
'default' => 'html',
'class' => 'email_type',
'options' => array(
'plain' => 'Plain text',
'html' => 'HTML',
'multipart' => 'Multipart'
)
)
);
}
/**
* get_content_html function.
*
* @since 0.1
* @return string
*/
public function get_content_html() {
ob_start();
woocommerce_get_template($this->template_html,array('project_name'=>$this->project_name,'order' => $this->object, 'email_heading' => $this->get_heading()),'',$this->template_base);
return ob_get_clean();
}
/**
* get_content_plain function.
*
* @since 0.1
* @return string
*/
public function get_content_plain() {
ob_start();
woocommerce_get_template($this->template_plain,array('project_name'=>$this->project_name,'order' => $this->object, 'email_heading' => $this->get_heading()),'',$this->template_base);
return ob_get_clean();
}
}
<?php
/**
* WC_Report_Sales_By_Date
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Reports
* @version 2.1.0
*/
class WC_Report_wc_quick_donation_reports extends WC_Admin_Report {
public $chart_colours = array();
/**
* Get the legend for the main chart sidebar
* @return array
*/
public function get_chart_legend() {
$legend = array();
$legend[] = array(
'title' => 'sales in this period',
'color' => $this->chart_colours['sales_amount'],
'highlight_series' => 6
);
return $legend;
}
/**
* Output the report
*/
public function output_report() {
$ranges = array(
'year' => __( 'Year', 'woocommerce' ),
'last_month' => __( 'Last Month', 'woocommerce' ),
'month' => __( 'This Month', 'woocommerce' ),
'7day' => __( 'Last 7 Days', 'woocommerce' )
);
$this->chart_colours = array(
'sales_amount' => '#3498db',
'average' => '#75b9e7',
'order_count' => '#b8c0c5',
'item_count' => '#d4d9dc',
'coupon_amount' => '#e67e22',
'shipping_amount' => '#1abc9c',
'refund_amount' => '#c0392b'
);
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day';
if ( ! in_array( $current_range, array( 'custom', 'year', 'last_month', 'month', '7day' ) ) ) {
$current_range = '7day';
}
$this->calculate_current_range( $current_range );
include( WC()->plugin_path() . '/includes/admin/views/html-report-by-date.php');
}
/**
* Output an export link
*/
public function get_export_button() {
$current_range = ! empty( $_GET['range'] ) ? sanitize_text_field( $_GET['range'] ) : '7day';
?>
<a
href="#"
download="report-<?php echo esc_attr( $current_range ); ?>-<?php echo date_i18n( 'Y-m-d', current_time('timestamp') ); ?>.csv"
class="export_csv"
data-export="chart"
data-xaxes="<?php _e( 'Date', 'woocommerce' ); ?>"
data-exclude_series="2"
data-groupby="<?php echo $this->chart_groupby; ?>"
>
<?php _e( 'Export CSV', 'woocommerce' ); ?>
</a>
<?php
}
/**
* Get the main chart
*
* @return string
*/
public function get_main_chart() {
global $wp_locale;
// Get orders and dates in range - we want the SUM of order totals, COUNT of order items, COUNT of orders, and the date
$orders = $this->get_order_report_data( array(
'data' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_sales'
),
'_order_shipping' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_shipping'
),
'ID' => array(
'type' => 'post_data',
'function' => 'COUNT',
'name' => 'total_orders',
'distinct' => true,
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date'
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
// Order items
$order_items = $this->get_order_report_data( array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count'
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date'
),
),
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'line_item',
'operator' => '='
)
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
// Get discount amounts in range
$coupons = $this->get_order_report_data( array(
'data' => array(
'order_item_name' => array(
'type' => 'order_item',
'function' => '',
'name' => 'order_item_name'
),
'discount_amount' => array(
'type' => 'order_item_meta',
'order_item_type' => 'coupon',
'function' => 'SUM',
'name' => 'discount_amount'
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date'
),
),
'where' => array(
array(
'key' => 'order_items.order_item_type',
'value' => 'coupon',
'operator' => '='
)
),
'group_by' => $this->group_by_query . ', order_item_name',
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_types' => wc_get_order_types( 'sales-reports' ),
'order_status' => array( 'completed', 'processing', 'on-hold', 'refunded' ),
) );
$partial_refunds = $this->get_order_report_data( array(
'data' => array(
'_refund_amount' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_refund'
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date'
)
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => false,
'parent_order_status' => array( 'completed', 'processing', 'on-hold' ),
) );
$full_refunds = $this->get_order_report_data( array(
'data' => array(
'_order_total' => array(
'type' => 'meta',
'function' => 'SUM',
'name' => 'total_refund'
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date'
),
),
'group_by' => $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true,
'order_status' => array( 'refunded' ),
) );
$refunds = array_merge($partial_refunds, $full_refunds);
// Prepare data for report
$order_counts = $this->prepare_chart_data( $orders, 'post_date', 'total_orders', $this->chart_interval, $this->start_date, $this->chart_groupby );
$order_item_counts = $this->prepare_chart_data( $order_items, 'post_date', 'order_item_count', $this->chart_interval, $this->start_date, $this->chart_groupby );
$order_amounts = $this->prepare_chart_data( $orders, 'post_date', 'total_sales', $this->chart_interval, $this->start_date, $this->chart_groupby );
$coupon_amounts = $this->prepare_chart_data( $coupons, 'post_date', 'discount_amount', $this->chart_interval, $this->start_date, $this->chart_groupby );
$shipping_amounts = $this->prepare_chart_data( $orders, 'post_date', 'total_shipping', $this->chart_interval, $this->start_date, $this->chart_groupby );
$refund_amounts = $this->prepare_chart_data( $refunds, 'post_date', 'total_refund', $this->chart_interval, $this->start_date, $this->chart_groupby );
// Encode in json format
$chart_data = json_encode( array(
'order_counts' => array_values( $order_counts ),
'order_item_counts' => array_values( $order_item_counts ),
'order_amounts' => array_values( $order_amounts ),
'coupon_amounts' => array_values( $coupon_amounts ),
'shipping_amounts' => array_values( $shipping_amounts ),
'refund_amounts' => array_values( $refund_amounts )
) );
?>
<div class="chart-container">
<div class="chart-placeholder main"></div>
</div>
<script type="text/javascript">
var main_chart;
jQuery(function(){
var order_data = jQuery.parseJSON( '<?php echo $chart_data; ?>' );
var drawGraph = function( highlight ) {
var series = [
{
label: "<?php echo esc_js( __( 'Number of items sold', 'woocommerce' ) ) ?>",
data: order_data.order_item_counts,
color: '<?php echo $this->chart_colours['item_count']; ?>',
bars: { fillColor: '<?php echo $this->chart_colours['item_count']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' },
shadowSize: 0,
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Number of orders', 'woocommerce' ) ) ?>",
data: order_data.order_counts,
color: '<?php echo $this->chart_colours['order_count']; ?>',
bars: { fillColor: '<?php echo $this->chart_colours['order_count']; ?>', fill: true, show: true, lineWidth: 0, barWidth: <?php echo $this->barwidth; ?> * 0.5, align: 'center' },
shadowSize: 0,
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Average sales amount', 'woocommerce' ) ) ?>",
data: [ [ <?php echo min( array_keys( $order_amounts ) ); ?>, <?php echo $this->average_sales; ?> ], [ <?php echo max( array_keys( $order_amounts ) ); ?>, <?php echo $this->average_sales; ?> ] ],
yaxis: 2,
color: '<?php echo $this->chart_colours['average']; ?>',
points: { show: false },
lines: { show: true, lineWidth: 2, fill: false },
shadowSize: 0,
hoverable: false
},
{
label: "<?php echo esc_js( __( 'Coupon amount', 'woocommerce' ) ) ?>",
data: order_data.coupon_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['coupon_amount']; ?>',
points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true },
lines: { show: true, lineWidth: 4, fill: false },
shadowSize: 0,
prepend_tooltip: "<?php echo get_woocommerce_currency_symbol(); ?>"
},
{
label: "<?php echo esc_js( __( 'Refund amount', 'woocommerce' ) ) ?>",
data: order_data.refund_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['refund_amount']; ?>',
points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true },
lines: { show: true, lineWidth: 4, fill: false },
shadowSize: 0,
prepend_tooltip: "<?php echo get_woocommerce_currency_symbol(); ?>"
},
{
label: "<?php echo esc_js( __( 'Shipping amount', 'woocommerce' ) ) ?>",
data: order_data.shipping_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['shipping_amount']; ?>',
points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true },
lines: { show: true, lineWidth: 4, fill: false },
shadowSize: 0,
prepend_tooltip: "<?php echo get_woocommerce_currency_symbol(); ?>"
},
{
label: "<?php echo esc_js( __( 'Sales amount', 'woocommerce' ) ) ?>",
data: order_data.order_amounts,
yaxis: 2,
color: '<?php echo $this->chart_colours['sales_amount']; ?>',
points: { show: true, radius: 5, lineWidth: 3, fillColor: '#fff', fill: true },
lines: { show: true, lineWidth: 4, fill: false },
shadowSize: 0,
prepend_tooltip: "<?php echo get_woocommerce_currency_symbol(); ?>"
}
];
if ( highlight !== 'undefined' && series[ highlight ] ) {
highlight_series = series[ highlight ];
highlight_series.color = '#9c5d90';
if ( highlight_series.bars )
highlight_series.bars.fillColor = '#9c5d90';
if ( highlight_series.lines ) {
highlight_series.lines.lineWidth = 5;
}
}
main_chart = jQuery.plot(
jQuery('.chart-placeholder.main'),
series,
{
legend: {
show: false
},
grid: {
color: '#aaa',
borderColor: 'transparent',
borderWidth: 0,
hoverable: true
},
xaxes: [ {
color: '#aaa',
position: "bottom",
tickColor: 'transparent',
mode: "time",
timeformat: "<?php if ( $this->chart_groupby == 'day' ) echo '%d %b'; else echo '%b'; ?>",
monthNames: <?php echo json_encode( array_values( $wp_locale->month_abbrev ) ) ?>,
tickLength: 1,
minTickSize: [1, "<?php echo $this->chart_groupby; ?>"],
font: {
color: "#aaa"
}
} ],
yaxes: [
{
min: 0,
minTickSize: 1,
tickDecimals: 0,
color: '#d4d9dc',
font: { color: "#aaa" }
},
{
position: "right",
min: 0,
tickDecimals: 2,
alignTicksWithAxis: 1,
color: 'transparent',
font: { color: "#aaa" }
}
],
}
);
jQuery('.chart-placeholder').resize();
}
drawGraph();
jQuery('.highlight_series').hover(
function() {
drawGraph( jQuery(this).data('series') );
},
function() {
drawGraph();
}
);
});
</script>
<?php
}
}
<?php
class WC_Quick_Donation_Settings extends WC_Settings_Page {
/**
* Constructor
*/
public function __construct() {
$this->id = 'wc_quick_donation';
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_tab' ), 50 );
add_action( 'woocommerce_sections_' . $this->id, array( $this, 'output_sections' ) );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
}
/**
* Add plugin options tab
*
* @return array
*/
public function add_settings_tab( $settings_tabs ) {
$settings_tabs[$this->id] = 'WC Quick Donation';
return $settings_tabs;
}
/**
* Get sections
*
* @return array
*/
public function get_sections() {
$sections = array(
'general' => __( 'General Settings', $this->id )
);
return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
}
/**
* Get sections
*
* @return array
*/
public function get_settings( $section = null ) {
global $wc_quick_buy;
switch( $section ){
case 'general' :
case '' :
$settings = array(
'section_title' => array(
'name' => 'Woocommerce Quick Donation Settings',
'type' => 'title',
'desc' => 'Just Call <code><strong>[wc_quick_donation]</strong></code> short code any where in your page,post,widgets or template <br/>
To Customize the <strong>Donation Form</strong> copy the template file from <code>woocommerce-quick-donation/template/donation_form.php</code> to your <code>theme/woocommerce</code> folder.
',
'id' => 'wc_quick_donation_section_title'
),
'remove_cart_items' => array(
'name' => 'Auto Remove Cart Items',
'desc' => 'Removes Other Cart Items If Donation Aded To Cart.',
'id' => 'wc_quick_donation_cart_remove',
'type' => 'select',
'class' =>'chosen_select',
'options' => array('false' => 'Keep All Items','true'=>'Remove All Items')
),
'redirect' => array(
'name' => 'Redirect User To',
'desc' => 'After Donation Added To Cart.',
'id' => 'wc_quick_donation_redirect',
'type' => 'select',
'class' =>'chosen_select',
'options' => array('checkout' => 'Checkout Page','cart'=>'Cart Page','false' => 'None')
),
'payment_gateway' => array(
'name' => 'Allowed Payment Gateway\'s',
'desc' => 'Select Payment Gateway for donation..',
'id' => 'wc_quick_donation_payment_gateway',
'type' => 'multiselect',
'class' =>'chosen_select',
'options' => $wc_quick_buy->get_payments_gateway()
),
'project_names' => array(
'name' => 'Project Names',
'type' => 'textarea',
'desc' => 'Add Names By <code>,</code> Seperated ',
'id' => 'wc_quick_donation_projects',
'default' => 'Project1,Project2'
),
'order_project_title' => array(
'name' => 'Order Project Title',
'type' => 'text',
'desc' => 'Title to view in order edit page',
'id' => 'wc_quick_donation_project_section_title',
'default' =>'For Project'
),
'order_notes_title' => array(
'name' => 'Order Notes Title',
'type' => 'text',
'desc' => 'to display project name use <code>Project Name : %s</code>',
'id' => 'wc_quick_donation_order_notes_title',
'default' =>'Project Name %s'
),
'section_end' => array(
'type' => 'sectionend',
'id' => 'wc_settings_tab_demo_section_end'
)
);
break;
case 'email_template':
break;
}
return apply_filters( 'wc_settings_tab_'.$this->id.'_settings', $settings, $section );
}
/**
* Output the settings
*/
public function output() {
global $current_section;
$settings = $this->get_settings( $current_section );
WC_Admin_Settings::output_fields( $settings );
}
/**
* Save settings
*/
public function save() {
global $current_section;
$settings = $this->get_settings( $current_section );
WC_Admin_Settings::save_fields( $settings );
}
}
return new WC_Quick_Donation_Settings();
?>
\ No newline at end of file
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
Plugin Name: Woocommerce Quick Donation Plugin Name: Woocommerce Quick Donation
Plugin URI: http://varunsridharan.in/ Plugin URI: http://varunsridharan.in/
Description: Woocommerce Quick Donation Description: Woocommerce Quick Donation
Version: 0.1 Version: 0.2
Author: Varun Sridharan Author: Varun Sridharan
Author URI: http://varunsridharan.in/ Author URI: http://varunsridharan.in/
License: GPL2 License: GPL2
...@@ -29,50 +29,50 @@ define( 'wc_qd_p', plugin_dir_path( __FILE__ ) ); ...@@ -29,50 +29,50 @@ define( 'wc_qd_p', plugin_dir_path( __FILE__ ) );
class wc_quick_donation{ class wc_quick_donation{
private $donation_id; private $donation_id;
private $plugin_slug;
/** /**
* Setup The Plugin Class * Setup The Plugin Class
*/ */
function __construct() { function __construct() {
add_action( 'admin_menu', array($this,'add_menu'));
add_filter( 'woocommerce_settings_tabs_array',array($this,'add_menu'), 50 );
add_action( 'woocommerce_settings_tabs_wc_quick_donation', array($this,'settings_page'));
add_action( 'woocommerce_update_options_wc_quick_donation', array($this,'update_settings') );
$this->donation_id = get_option('wc_quick_donation_product_id'); $this->donation_id = get_option('wc_quick_donation_product_id');
add_shortcode( 'wc_quick_donation', array($this,'shortcode_handler' )); add_shortcode( 'wc_quick_donation', array($this,'shortcode_handler' ));
add_action('init',array($this,'process_donation'));
add_filter('woocommerce_get_price', array($this,'get_price'),10,2);
add_action('wc_qd_show_projects_list',array($this,'get_projects_list'));
add_action('woocommerce_checkout_update_order_meta', array($this,'add_order_meta'));
add_action( 'woocommerce_admin_order_data_after_billing_address', array($this,'my_custom_checkout_field_display_admin_order_meta'), 10, 1 );
}
add_action( 'init',array($this,'process_donation'));
add_action( 'wc_qd_show_projects_list',array($this,'get_projects_list'));
add_action( 'woocommerce_checkout_update_order_meta', array($this,'add_order_meta'));
add_action( 'woocommerce_available_payment_gateways',array($this,'remove_gateway'));
add_action( 'woocommerce_admin_order_data_after_billing_address', array($this,'custom_order_details_page_info'), 10, 1 );
add_filter( 'woocommerce_get_price', array($this,'get_price'),10,2);
add_filter( 'woocommerce_get_settings_pages', array($this,'settings_page') );
add_filter( 'woocommerce_email_classes', array($this,'email_classes'));
}
/** /**
* Add a new settings tab to the WooCommerce settings tabs array. * Adds Settings Page
*
* @param array $settings_tabs Array of WooCommerce setting tabs & their labels, excluding the Subscription tab.
* @return array $settings_tabs Array of WooCommerce setting tabs & their labels, including the Subscription tab.
*/ */
public function add_menu($settings_tabs){ public function settings_page( $settings ) {
$settings_tabs['wc_quick_donation'] = 'WC Quick Donation'; $settings[] = include( wc_qd_p.'woocommerce-quick-donation-settings.php' );
return $settings_tabs; return $settings;
} }
/** /**
* Uses the WooCommerce admin fields API to output settings via the @see woocommerce_admin_fields() function. * Adds Email Classes
*
* @uses woocommerce_admin_fields()
* @uses self::get_settings()
*/ */
public static function settings_page() { public function email_classes($email_classes){
woocommerce_admin_fields( self::get_settings() ); require_once( wc_qd_p.'woocommerce-quick-donation-email-processing.php' );
require_once( wc_qd_p.'woocommerce-quick-donation-email-completed.php' );
$email_classes['wc_quick_donation_processing_donation_email'] = new wc_quick_donation_processing_donation_email();
$email_classes['wc_quick_donation_completed_donation_email'] = new wc_quick_donation_completed_donation_email();
return $email_classes;
} }
/**
* Adds Donation Order Meta. [Project Name]
* @param [[Type]] $order_id [[Description]]
*/
public function add_order_meta( $order_id ) { public function add_order_meta( $order_id ) {
global $woocommerce; global $woocommerce;
update_post_meta( $order_id, 'project_details',$woocommerce->session->projects); update_post_meta( $order_id, 'project_details',$woocommerce->session->projects);
...@@ -81,92 +81,54 @@ class wc_quick_donation{ ...@@ -81,92 +81,54 @@ class wc_quick_donation{
$format = sprintf(get_option('wc_quick_donation_order_notes_title'), $woocommerce->session->projects); $format = sprintf(get_option('wc_quick_donation_order_notes_title'), $woocommerce->session->projects);
$order->add_order_note($format); $order->add_order_note($format);
unset($order); unset($order);
$this->update_order_id($order_id);
} }
public function my_custom_checkout_field_display_admin_order_meta($order){ /**
echo '<p><strong>'.get_option('wc_quick_donation_project_section_title').' :</strong>'.get_post_meta( $order->id, 'project_details', true ) . '</p>'; * Updates Order ID to [wc_quick_donation_orders] when donation is ordered
* @param [int] $order_id [Donation Order ID]
* @since 1.0
*/
private function update_order_id($order_id){
$ordersID = get_option('wc_quick_donation_orders');
$save_order_id = array();
if(empty($ordersID)){
$save_order_id[] = $order_id;
} else {
$save_order_id = json_decode($ordersID,true);
$save_order_id[] = $order_id;
} }
update_option('wc_quick_donation_orders',json_encode($save_order_id));
}
/** /**
* Get all the settings for this plugin for @see woocommerce_admin_fields() function. * Custom Title In Order View Page
* * @since 1.0
* @return array Array of settings for @see woocommerce_admin_fields() function.
*/ */
public static function get_settings() { public function custom_order_details_page_info($order){
echo '<p><strong>'.get_option('wc_quick_donation_project_section_title').' :</strong>'.get_post_meta( $order->id, 'project_details', true ) . '</p>';
$settings = array(
'section_title' => array(
'name' => 'Woocommerce Quick Donation Settings',
'type' => 'title',
'desc' => 'Just Call <code><strong>[wc_quick_donation]</strong></code> short code any where in your page,post,widgets or template <br/>
To Customize the <strong>Donation Form</strong> copy the template file from <code>woocommerce-quick-donation/template/donation_form.php</code> to your <code>theme/woocommerce</code> folder.
',
'id' => 'wc_quick_donation_section_title'
),
'donate_redirect' => array(
'name' => 'Donation Redirect',
'desc' => 'Redirect User Checkout If Added To Cart.',
'id' => 'wc_quick_donation_redirect',
'type' => 'select',
'class' =>'chosen_select',
'options' => array('false' => 'No Redirect','true'=>'Redirect To Checkout Page')
),
'donate_redirect' => array(
'name' => 'Remove Cart Items',
'desc' => 'Removes Other Cart Items If Donation Aded To Cart.',
'id' => 'wc_quick_donation_cart_remove',
'type' => 'select',
'class' =>'chosen_select',
'options' => array('false' => 'Keep All Items','true'=>'Remove All Items')
),
'project_names' => array(
'name' => 'Project Names',
'type' => 'textarea',
'desc' => 'Add Names By <code>,</code> Seperated ',
'id' => 'wc_quick_donation_projects',
'default' => 'Project1,Project2'
),
'order_project_title' => array(
'name' => 'Order Project Title',
'type' => 'text',
'desc' => 'Title to view in order edit page',
'id' => 'wc_quick_donation_project_section_title',
'default' =>'For Project'
),
'order_notes_title' => array(
'name' => 'Order Notes Title',
'type' => 'text',
'desc' => 'to display project name use <code>Project Name : %s</code>',
'id' => 'wc_quick_donation_order_notes_title',
'default' =>'Project Name %s'
),
'section_end' => array(
'type' => 'sectionend',
'id' => 'wc_settings_tab_demo_section_end'
)
);
return apply_filters( 'wc_settings_tab_demo_settings', $settings );
} }
/** /**
* Uses the WooCommerce options API to save settings via the @see woocommerce_update_options() function. * Get All Enabled And Avaiable Payment Gateway To List In Settings Page
* * @returns array [Aviable Gateways]
* @uses woocommerce_update_options()
* @uses self::get_settings()
*/ */
public static function update_settings() { public function get_payments_gateway(){
woocommerce_update_options(self::get_settings()); $payment = WC()->payment_gateways->payment_gateways();
$gateways = array();
foreach($payment as $gateway){
if ( $gateway->enabled == 'yes' ){
$gateways[$gateway->id] = $gateway->title;
}
}
return $gateways;
} }
/** /**
...@@ -187,6 +149,18 @@ class wc_quick_donation{ ...@@ -187,6 +149,18 @@ class wc_quick_donation{
} }
/**
* Check's For Donation Product Exist In Cart
* @returns Boolean True|False
*/
public function only_donation_exsits(){
global $woocommerce;
if( sizeof($woocommerce->cart->get_cart()) == 1 && $this->donation_exsits()){
return true;
}
return false;
}
/** /**
* Gets Donation Current Price * Gets Donation Current Price
* @param $price * @param $price
...@@ -202,20 +176,31 @@ class wc_quick_donation{ ...@@ -202,20 +176,31 @@ class wc_quick_donation{
} }
/** /**
* Process The Given Donation * Process The Given Donation
*/ */
public function process_donation(){ public function process_donation(){
global $woocommerce; global $woocommerce;
$donation = isset($_POST['jc-donation']) && !empty($_POST['jc-donation']) ? floatval($_POST['jc-donation']) : false;
if(isset($_POST['donation_add'])){
$error = 0;
$found = false;
$donation = isset($_POST['donation_ammount']) && !empty($_POST['donation_ammount']) ? floatval($_POST['donation_ammount']) : false;
$projects = isset($_POST['projects']) && !empty($_POST['projects']) ? $_POST['projects'] : false; $projects = isset($_POST['projects']) && !empty($_POST['projects']) ? $_POST['projects'] : false;
$_SESSION['wc_qd_projects'] = $projects; $_SESSION['wc_qd_projects'] = $projects;
if($donation && isset($_POST['donate-btn'])){ if(!$donation){
$found = false; wc_add_notice('Invalid Donation Ammount', 'error' );
$error += 1;
}
if(isset($_POST['projects']) && $_POST['projects'] == '' ){
wc_add_notice('Please Select A Project', 'error' );
$error += 1;
}
if($error ==0 ) {
if($donation >= 0){ if($donation >= 0){
$woocommerce->session->jc_donation = $donation; $woocommerce->session->jc_donation = $donation;
$woocommerce->session->projects = $projects; $woocommerce->session->projects = $projects;
...@@ -227,18 +212,68 @@ class wc_quick_donation{ ...@@ -227,18 +212,68 @@ class wc_quick_donation{
} }
if(!$found) if(!$found)
$this->remove_cart_items(); $this->add_donation_cart();
$woocommerce->cart->add_to_cart($this->donation_id);
$this->donation_redirect();
}else{ }else{
$this->add_donation_cart();
}
}
}
}
}
/**
* Adds Donation Product To Cart
*/
private function add_donation_cart(){
global $woocommerce;
$this->remove_cart_items(); $this->remove_cart_items();
$woocommerce->cart->add_to_cart($this->donation_id); $woocommerce->cart->add_to_cart($this->donation_id);
$this->donation_redirect(); $this->redirectCART();
} }
/**
* Redirect To Checkout Page After Donation is Added
*/
public function redirectCART(){
global $woocommerce;
$redirect_op = get_option('wc_quick_donation_redirect');
if($redirect_op == 'cart'){
wp_safe_redirect(WC()->cart->get_cart_url() );exit;
} else if($redirect_op == 'checkout'){
wp_safe_redirect(WC()->cart->get_checkout_url() );exit;
} }
} }
/**
* Allowes only selected payment gateway for donation product.
* @since 0.2
* @access public
*/
public function remove_gateway($gateway){
if($this->donation_exsits() && $this->only_donation_exsits()){
$payments = get_option('wc_quick_donation_payment_gateway');
if(!empty($payments)){
foreach($gateway as $val){
if(! in_array($val->id,$payments)){
unset($gateway[$val->id]);
}
}
}
return $gateway;
}
return $gateway;
} }
/**
* Removes Cart ITEM if donation is added
* @returns Boolean [[Description]]
*/
private function remove_cart_items(){ private function remove_cart_items(){
$cart_remove = get_option('wc_quick_donation_cart_remove'); $cart_remove = get_option('wc_quick_donation_cart_remove');
if(isset($cart_remove) && $cart_remove == 'true'){ if(isset($cart_remove) && $cart_remove == 'true'){
...@@ -250,26 +285,18 @@ class wc_quick_donation{ ...@@ -250,26 +285,18 @@ class wc_quick_donation{
} }
public function donation_redirect(){ /**
global $woocommerce; * Gets Donation Form.
$redirect = get_option('wc_quick_donation_redirect'); */
if(isset($redirect) && $redirect == 'true'){
wp_safe_redirect($woocommerce->cart->get_checkout_url() );
exit;
}
return '';
}
public function wc_qd_form(){ public function wc_qd_form(){
global $woocommerce; global $woocommerce;
$donate = isset($woocommerce->session->jc_donation) ? floatval($woocommerce->session->jc_donation) : 0; $donate = isset($woocommerce->session->jc_donation) ? floatval($woocommerce->session->jc_donation) : 0;
if(!$this->donation_exsits()){ if(!$this->donation_exsits()){
unset($woocommerce->session->jc_donation); unset($woocommerce->session->jc_donation);
unset($woocommerce->session->projects); unset($woocommerce->session->projects);
} }
// uncomment the next line of code if you wish to round up the order total with the donation e.g. £53 = £7 donation
// $donate = jc_round_donation($woocommerce->cart->total ); // $donate = jc_round_donation($woocommerce->cart->total );
if(!$this->donation_exsits()){ if(!$this->donation_exsits()){
$wc_get_template = function_exists('wc_get_template') ? 'wc_get_template' : 'woocommerce_get_template'; $wc_get_template = function_exists('wc_get_template') ? 'wc_get_template' : 'woocommerce_get_template';
...@@ -278,7 +305,9 @@ class wc_quick_donation{ ...@@ -278,7 +305,9 @@ class wc_quick_donation{
} }
#$before,$after,$select_class,$select_id /**
* Generates Select Box For Projects List
*/
public function get_projects_list(){ public function get_projects_list(){
$projects_db = get_option('wc_quick_donation_projects'); $projects_db = get_option('wc_quick_donation_projects');
...@@ -312,6 +341,18 @@ class wc_quick_donation{ ...@@ -312,6 +341,18 @@ class wc_quick_donation{
if($exist){ if($exist){
return true; return true;
} else { } else {
$post_id = $this->create_donation();
add_option('wc_quick_donation_product_id',$post_id);
add_option('wc_quick_donation_orders','');
add_site_option( 'wc_quick_donation_product_id', $post_id) ;
}
}
/**
* Creats Donation Product IN WC
* @returns [[Type]] [[Description]]
*/
public function create_donation(){
$userID = 1; $userID = 1;
if(get_current_user_id()){ if(get_current_user_id()){
$userID = get_current_user_id(); $userID = get_current_user_id();
...@@ -336,9 +377,7 @@ class wc_quick_donation{ ...@@ -336,9 +377,7 @@ class wc_quick_donation{
update_post_meta($post_id, '_manage_stock', "no" ); update_post_meta($post_id, '_manage_stock', "no" );
update_post_meta($post_id, '_sold_individually', "yes" ); update_post_meta($post_id, '_sold_individually', "yes" );
update_post_meta($post_id, '_sku', 'checkout-donation'); update_post_meta($post_id, '_sku', 'checkout-donation');
add_option('wc_quick_donation_product_id',$post_id); return $post_id;
add_site_option( 'wc_quick_donation_product_id', $post_id) ;
}
} }
} }
...@@ -354,5 +393,4 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g ...@@ -354,5 +393,4 @@ if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', g
} }
?> ?>
\ No newline at end of file
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