Commit b17a8087 authored by Varun Sridharan's avatar Varun Sridharan

Released 1.3.3 BETA

* Moved Few DB functions from Functions class to db class
* Fixed template override issue
[https://github.com/technofreaky/woocomerce-quick-donation/issues/12]
* Removed Unwated Metabox For Donation order Page
parent 9c660c91
......@@ -19,7 +19,7 @@ class WooCommerce_Quick_Donation_Admin_Function {
public function __construct(){
add_action( 'post_row_actions', array($this,'protect_donation_product'),99,2);
add_filter( 'pre_get_posts', array($this,'hide_donation_order_woocommerce_order'));
add_action( 'parse_query', array( $this, 'hide_donation_order_woocommerce_order' ) );
add_filter( 'wc_order_types',array($this,'add_wc_order_types'),99,2);
}
......@@ -29,6 +29,7 @@ class WooCommerce_Quick_Donation_Admin_Function {
public function hide_donation_order_woocommerce_order($query) {
global $pagenow,$post_type;
$query = $query;
if(!defined('WC_QD_QRY_OVERRIDE')){
if( 'edit.php' == $pagenow || $query->is_admin && 'shop_order' == $post_type){
$query->set('meta_query',array('relation' => 'AND', array('key' => '_is_donation','compare' => 'NOT EXISTS')));
......
......@@ -28,7 +28,6 @@ class WooCommerce_Quick_Donation_Admin {
public function load_required_files(){
WC_QD()->load_files(WC_QD_ADMIN.'metabox_framework/meta-box.php');
}
public function init_hooks(){
......@@ -84,6 +83,7 @@ class WooCommerce_Quick_Donation_Admin {
*/
public function init_admin_class(){
$this->functions = new WooCommerce_Quick_Donation_Admin_Function;
$this->admin_order_page = new WooCommerce_Quick_Donation_Admin_Order_Page_Functions;
}
......
<?php
/**
* The admin-specific functionality of the plugin.
*
* @link https://wordpress.org/plugins/woocommerce-role-based-price/
*
* The admin-specific functionality of the plugin.
*
* Defines the plugin name, version, and two examples hooks for how to
* enqueue the admin-specific stylesheet and JavaScript.
*
* @package @TODO
* @subpackage @TODO
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Admin_Order_Page_Functions {
public function __construct(){
add_action('add_meta_boxes_shop_order',array($this,'remove_metabox'),99,2);
}
public function remove_metabox($post){
$is_donation = WC_QD()->db()->_is_donation($post->ID);
if($is_donation){
remove_meta_box('woocommerce-order-items','shop_order','normal');
remove_meta_box('woocommerce-order-downloads','shop_order','normal');
}
}
}
?>
\ No newline at end of file
......@@ -23,13 +23,8 @@ class WooCommerce_Quick_Donation_Admin_Settings {
* @return [[Type]] [[Description]]
*/
public function get_settings_page(){
$this->settings_pages[] = array('name' => __( 'Tab 2',WC_QD_TXT),
'type' => 'heading'
);
$this->settings_pages[] = array('name' => __( 'Tab 2',WC_QD_TXT),
'type' => 'heading'
);
$this->settings_pages[] = array('name' => __( 'Tab 2',WC_QD_TXT), 'type' => 'heading');
$this->settings_pages[] = array('name' => __( 'Tab 2',WC_QD_TXT), 'type' => 'heading');
$this->settings_pages = apply_filters('wc_quick_donation_settings_tab',$this->settings_pages);
return $this->settings_pages;
}
......@@ -74,7 +69,6 @@ class WooCommerce_Quick_Donation_Admin_Settings {
}
function admin_init() {
$pages = $this->settings->add_pages($this->get_settings_page());
$sections = $this->get_settings_section();
$fields = $this->get_settings_fields();
......@@ -83,16 +77,11 @@ class WooCommerce_Quick_Donation_Admin_Settings {
}
foreach($fields as $page_id => $fields){
foreach($fields as $section_id => $field){
$pages = $this->settings->add_fields($page_id, $section_id, $field );
}
}
// Create a $pages array with the add_page(), add_pages(), add_section(), add_sections(), add_field() and add_fields() methods.
$this->settings->init( $pages, $this->page_hook );
}
......@@ -100,14 +89,12 @@ class WooCommerce_Quick_Donation_Admin_Settings {
echo '<div class="wrap">';
settings_errors();
$this->settings->render_header( __( 'WP Settings Example', 'plugin-text-domain' ) );
echo $this->settings->debug;
//echo $this->settings->debug;
// Use the function get_settings() to get all the settings.
$settings = $this->settings->get_settings();
// Use the function get get_current_admin_page() to check what page you're on
// $page = $this->settings->get_current_admin_page();
// $current_page = $page['id'];
// Display the form(s).
$this->settings->render_form();
echo '</div>';
......
......@@ -45,6 +45,16 @@ $fields['settings_message']['message'][] = array(
'type' => 'textarea'
);
$fields['settings_message']['message'][] = array(
'label' => __( 'Donation Already Exist', WC_QD_TXT),
'desc' => __( 'Custom Message To Show When User Trying To Add Another Donation To Cart',WC_QD_TXT),
'id' => WC_QD_DB.'donation_already_exist',
'attr' => array('style' => 'min-width:35%; width:auto;max-width:75%;'),
'type' => 'textarea',
);
$fields['settings_message']['message'][] = array(
'label' => __( 'Invalid Donation Amount', WC_QD_TXT),
'desc' => __( 'Custom Message To Show When Invalid Donation Entered',WC_QD_TXT),
......
......@@ -7,5 +7,5 @@ $section['settings_message'][] = array(
'id'=>'message',
'title'=>'Donation Error :',
'desc' => '',
'validate_callback'=>true,
'validate_callback'=>array( $this, 'validate_section' ),
);
......@@ -122,12 +122,12 @@ class WooCommerce_Quick_Donation_Settings {
}
function validate_section( $fields ) {
global $send_fields; $send_fields = $fields;
include(WC_QD_ADMIN.'settings/validate.php');
return $fields;
}
//function validate_section( $fields ) {
// global $send_fields;
// $send_fields = $fields;
// include(WC_QD_ADMIN.'settings/validate.php');
// return $fields;
//}
function get_option($id = ''){
if( ! empty($this->settings_values) && ! empty($id)){
......
......@@ -15,6 +15,9 @@ class WC_QD_INSTALL{
update_option(WC_QD_DB.'product_id',$post_id);
}
/**
* Checks Upgrade Status
*/
public static function check_db_version(){
$current_version = get_option(WC_QD_DB.'db_version');
if(! $current_version){
......@@ -34,6 +37,9 @@ class WC_QD_INSTALL{
return false;
}
/**
* Create Quick Donation Table
*/
public static function wc_qd_table_install() {
global $wpdb;
global $jal_db_version;
......@@ -54,11 +60,13 @@ class WC_QD_INSTALL{
dbDelta( $sql );
}
/**
* Create Donation Product In WooCommerce
* @return int donation Post id
*/
public static function create_donation(){
$userID = 1;
if(get_current_user_id()){
$userID = get_current_user_id();
}
if(get_current_user_id()){ $userID = get_current_user_id(); }
$post = array(
'post_author' => $userID,
......
......@@ -3,12 +3,18 @@ if ( ! defined( 'WPINC' ) ) { die; }
class WC_QD_Post_Types {
/**
* Inits Post Types Class
*/
public static function init(){
add_action( 'init', array(__CLASS__,'register_donation_posttype'),5);
add_action( 'init', array(__CLASS__,'register_donation_category'),5);
add_action( 'init', array(__CLASS__,'register_donation_tags' ), 5 );
}
/**
* Registers Donation Post Type
*/
public static function register_donation_posttype(){
$args = array(
'label' => __( 'Quick Donation Project', WC_QD_TXT ),
......@@ -32,9 +38,11 @@ class WC_QD_Post_Types {
'capability_type' => 'page',
);
register_post_type( WC_QD_PT, $args );
}
/**
* Post Types Labels
*/
public static function get_post_types_labels() {
return array(
'name' => _x( 'Quick Donation Projects', 'Post Type General Name', WC_QD_TXT ),
......@@ -55,6 +63,9 @@ class WC_QD_Post_Types {
);
}
/**
* Returns Post Type Rewrites
*/
public static function get_posttype_rewrite(){
return array(
'slug' => 'donations',
......@@ -66,6 +77,9 @@ class WC_QD_Post_Types {
/**
* Registers Post Type Category
*/
public static function register_donation_category(){
$labels = array(
......@@ -110,7 +124,9 @@ class WC_QD_Post_Types {
/**
* Registers Donation Tags
*/
public static function register_donation_tags() {
$labels = array(
......
......@@ -7,6 +7,44 @@ if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_DB {
/**
* Internal Post Meta Function
*/
protected function post_meta($id,$meta_key,$single = false){
return get_post_meta($id,$meta_key,$single);
}
public function get_message($id,$search_replace = array()){
if($id == null){ return false; }
$text = WC_QD()->settings()->get_option($id);
$replaced_text = str_replace(array_keys($search_replace),array_values($search_replace),$text);
return $replaced_text;
}
public function min_project($id){
$value = intval($this->post_meta($id,'_'.WC_QD_DB.'min_req_donation',true));
if($value > 0){ return $value;}
return false;
}
public function max_project($id){
$value = intval($this->post_meta($id,'_'.WC_QD_DB.'max_req_donation',true));
if($value > 0){ return $value;}
return false;
}
public function project_status($id){
return $this->post_meta($id,'_'.WC_QD_DB . 'visibility_project',true);
}
public function _is_donation($id){
$status = intval($this->post_meta($id,'_is_donation',true));
if($status == 1){return true;}
return false;
}
public function add_db_option($order_id,$project_id,$user_id){
global $wpdb;
$data_c = array('date' => current_time( 'mysql' ),'userid' => $user_id,'donationid' => $order_id,'projectid' => $project_id);
......
......@@ -153,6 +153,8 @@ class WooCommerce_Quick_Donation_Functions {
}
public function wc_locate_template($template_full_path,$template_name,$template_dir){
if(file_exists($template_full_path)){ return $template_full_path; }
$template_full_path = $template_full_path;
if(isset(self::$search_template['general'][$template_name])){
......@@ -177,41 +179,6 @@ class WooCommerce_Quick_Donation_Functions {
return $gateways;
}
/**
* Internal Post Meta Function
*/
protected function post_meta($id,$meta_key,$single = false){
return get_post_meta($id,$meta_key,$single);
}
public function min_project($id){
$value = intval($this->post_meta($id,'_'.WC_QD_DB.'min_req_donation',true));
if($value > 0){ return $value;}
return false;
}
public function max_project($id){
$value = intval($this->post_meta($id,'_'.WC_QD_DB.'max_req_donation',true));
if($value > 0){ return $value;}
return false;
}
public function project_status($id){
return $this->post_meta($id,'_'.WC_QD_DB . 'visibility_project',true);
}
public function get_message($id,$search_replace = array()){
if($id == null){ return false; }
$text = WC_QD()->settings()->get_option($id);
$replaced_text = str_replace(array_keys($search_replace),array_values($search_replace),$text);
return $replaced_text;
}
public function get_admin_pay_gate(){
$gateway = $this->get_payment_gateways();
if(! empty($gateway)){
......
......@@ -13,8 +13,6 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
parent::__construct();
add_action( 'wp_loaded',array($this,'on_wp_loaded'),20);
add_filter( 'woocommerce_get_price', array($this,'get_price'),10,2);
}
public function on_wp_loaded(){
......@@ -24,50 +22,60 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
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( 'woocommerce_cart_item_name', array($this,'change_donation_name'));
}
$this->process_donation();
}
public function change_donation_name(){
$post_id = $this->get_checkout_project_id();
$title = get_the_title($post_id);
return $title;
}
public function remove_email_actions($email_class ){
// New order emails
$email = $email_class;
remove_action('woocommerce_order_status_pending_to_processing_notification',
array($email_class->emails['WC_Email_New_Order'],'trigger'));
array($email->emails['WC_Email_New_Order'],'trigger'));
remove_action('woocommerce_order_status_pending_to_completed_notification',
array($email_class->emails['WC_Email_New_Order'],'trigger'));
array($email->emails['WC_Email_New_Order'],'trigger'));
remove_action('woocommerce_order_status_pending_to_on-hold_notification',
array($email_class->emails['WC_Email_New_Order'],'trigger'));
array($email->emails['WC_Email_New_Order'],'trigger'));
remove_action('woocommerce_order_status_failed_to_processing_notification',
array($email_class->emails['WC_Email_New_Order'],'trigger'));
array($email->emails['WC_Email_New_Order'],'trigger'));
remove_action('woocommerce_order_status_failed_to_completed_notification',
array($email_class->emails['WC_Email_New_Order'],'trigger'));
array($email->emails['WC_Email_New_Order'],'trigger'));
remove_action('woocommerce_order_status_failed_to_on-hold_notification',
array($email_class->emails['WC_Email_New_Order'],'trigger'));
array($email->emails['WC_Email_New_Order'],'trigger'));
// Processing order emails
remove_action('woocommerce_order_status_pending_to_processing_notification',
array($email_class->emails['WC_Email_Customer_Processing_Order'],'trigger'));
array($email->emails['WC_Email_Customer_Processing_Order'],'trigger'));
remove_action('woocommerce_order_status_pending_to_on-hold_notification',
array($email_class->emails['WC_Email_Customer_Processing_Order'],'trigger'));
array($email->emails['WC_Email_Customer_Processing_Order'],'trigger'));
// Completed order emails
remove_action('woocommerce_order_status_completed_notification',
array($email_class->emails['WC_Email_Customer_Completed_Order'],'trigger'));
array($email->emails['WC_Email_Customer_Completed_Order'],'trigger'));
// New order emails
add_action('woocommerce_order_status_pending_to_processing_notification',
array($email_class->emails[WC_QD_DB.'new_donation_email'],'trigger'));
array($email->emails[WC_QD_DB.'new_donation_email'],'trigger'));
add_action('woocommerce_order_status_pending_to_completed_notification',
array($email_class->emails[WC_QD_DB.'new_donation_email'],'trigger'));
array($email->emails[WC_QD_DB.'new_donation_email'],'trigger'));
add_action('woocommerce_order_status_pending_to_on-hold_notification',
array($email_class->emails[WC_QD_DB.'new_donation_email'],'trigger'));
array($email->emails[WC_QD_DB.'new_donation_email'],'trigger'));
add_action('woocommerce_order_status_failed_to_processing_notification',
array($email_class->emails[WC_QD_DB.'new_donation_email'],'trigger'));
array($email->emails[WC_QD_DB.'new_donation_email'],'trigger'));
add_action('woocommerce_order_status_failed_to_completed_notification',
array($email_class->emails[WC_QD_DB.'new_donation_email'],'trigger'));
array($email->emails[WC_QD_DB.'new_donation_email'],'trigger'));
add_action('woocommerce_order_status_failed_to_on-hold_notification',
array($email_class->emails[WC_QD_DB.'new_donation_email'],'trigger'));
array($email->emails[WC_QD_DB.'new_donation_email'],'trigger'));
......@@ -76,6 +84,12 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
public function process_donation(){
if(isset($_POST['donation_add'])){
if($this->check_donation_already_exist()){
$message = WC_QD()->db()->get_message(WC_QD_DB.'donation_already_exist');
wc_add_notice($message,'error');
return ;
}
global $woocommerce;
$donateprice = isset($_POST['wc_qd_donate_project_price']) ? $_POST['wc_qd_donate_project_price'] : false;
$projects = isset($_POST['wc_qd_donate_project_name']) && !empty($_POST['wc_qd_donate_project_name']) ? $_POST['wc_qd_donate_project_name'] : false;
......@@ -97,18 +111,26 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
$this->is_donation_exists = true;
$this->redirect_cart();
wc_add_notice('Success','success');
}
}
}
public function check_donation_already_exist(){
global $woocommerce;
foreach($woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
if( self::$donation_id == $_product->id ) { return true; }
}
return false;
}
public function check_donation_price_status($price){
if(empty($price)){
$message = WC_QD()->f()->get_message(WC_QD_DB.'empty_donation_msg');
$message = WC_QD()->db()->get_message(WC_QD_DB.'empty_donation_msg');
wc_add_notice($message,'error');
return false;
}
......@@ -116,7 +138,7 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
if(empty($price) || ! is_int($price) && $price == 0){
$id = WC_QD_DB.'invalid_donation_msg';
$search_replace = array('{donation_amount}' => $price);
$message = WC_QD()->f()->get_message($id,$search_replace);
$message = WC_QD()->db()->get_message($id,$search_replace);
wc_add_notice($message,'error');
return false;
}
......@@ -126,8 +148,8 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
public function check_min_max($project_id,$price){
$min_required = $this->f()->min_project($project_id);
$max_required = $this->f()->max_project($project_id);
$min_required = $this->db()->min_project($project_id);
$max_required = $this->db()->max_project($project_id);
$price = intval($price);
if($min_required){
......@@ -135,7 +157,7 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
if($price < $min_required){
$id = WC_QD_DB.'min_rda_msg';
$search_replace = array('{donation_amount}' => $price, '{min_amount}' => $min_required);
$message = WC_QD()->f()->get_message($id,$search_replace);
$message = WC_QD()->db()->get_message($id,$search_replace);
wc_add_notice($message,'error');
return false;
}
......@@ -147,7 +169,7 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
if($price > $max_required){
$id = WC_QD_DB.'max_rda_msg';
$search_replace = array('{donation_amount}' => $price, '{max_amount}' => $max_required);
$message = WC_QD()->f()->get_message($id,$search_replace);
$message = WC_QD()->db()->get_message($id,$search_replace);
wc_add_notice($message,'error');
return false;
}
......@@ -187,9 +209,14 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
global $woocommerce;
$project_id = intval($woocommerce->session->projects);
$user_id = get_current_user_id();
WC_QD()->db()->add_db_option($order_id,$project_id,$user_id);
}
public function get_checkout_project_id(){
global $woocommerce;
$post_id = $woocommerce->session->projects;
return $post_id;
}
/**
......
......@@ -6,7 +6,7 @@ Requires at least: 3.0 or higher
Tested up to: 4.4
WC requires at least: 1.0
WC tested up to: 2.4.8
Stable tag: 1.3.2 Beta
Stable tag: 1.3.3 Beta
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
......@@ -160,14 +160,33 @@ Yes you can! Join in on our <a href="https://github.com/technofreaky/woocomerce-
== Changelog ==
= 1.3.2 BETA
* Fixed Quick Donation Menu Not Listed In Some WP Settings.
= 1.3.3 BETA =
**Fixes**
* Moved Few DB functions from Functions class to db class
* Fixed template override issue [https://github.com/technofreaky/woocomerce-quick-donation/issues/12]
* Removed Unwated Metabox For Donation order Page
= 1.3.2 BETA =
**New**
* Added Quick Links At Plugin Listing Table
* Error Message When User Trying To Add Another Donation To Cart
* Already Exist Donation Error Message Option Added In Settings
**Tweaks**
* Standardized Coding
* Settings Page Modified
**Fixes**
* Changed `Donation` Name To `Project Name` at Checkout in Review Order Section
* Quick Donation Menu Not Listed In Some WP Settings.
= 1.3.1 Beta =
* Fixed Error At WooCommerce Settings Page
= 1.3.1 BETA =
**Fixes**
* Error At WooCommerce Settings Page
= 1.3 Beta =
**New**
* Created Separate Custom Post Type For Donation
* Created Separate Custom Settings Page
* Total Plugin Redeveloped
......
......@@ -14,7 +14,7 @@ if ( ! defined( 'ABSPATH' ) ) {
<table class="shop_table woocommerce-checkout-review-order-table">
<thead>
<tr>
<th class="product-name"><?php _e( 'Product', 'woocommerce' ); ?></th>
<th class="product-name"><?php _e( 'Donation for', 'woocommerce' ); ?></th>
<th class="product-total"><?php _e( 'Total', 'woocommerce' ); ?></th>
</tr>
</thead>
......@@ -29,8 +29,12 @@ if ( ! defined( 'ABSPATH' ) ) {
?>
<tr class="<?php echo esc_attr( apply_filters( 'woocommerce_cart_item_class', 'cart_item', $cart_item, $cart_item_key ) ); ?>">
<td class="product-name">
<?php echo apply_filters( 'woocommerce_cart_item_name', $_product->get_title(), $cart_item, $cart_item_key ) . '&nbsp;'; ?>
<?php echo apply_filters( 'woocommerce_checkout_cart_item_quantity', ' <strong class="product-quantity">' . sprintf( '&times; %s', $cart_item['quantity'] ) . '</strong>', $cart_item, $cart_item_key ); ?>
<?php
$project = apply_filters('woocommerce_cart_item_name', $_product->get_title(),$cart_item,$cart_item_key);
echo '<strong>'.$project.'</strong>';
?>
<?php echo WC()->cart->get_item_data( $cart_item ); ?>
</td>
<td class="product-total">
......
......@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Quick Donation
* Plugin URI: https://wordpress.org/plugins/woocommerce-plugin-boiler-plate/
* Description: Turns WooCommerce Into Online Donation
* Version: 1.3.2 BETA
* Version: 1.3.3 BETA
* Author: Varun Sridharan
* Author URI: http://varunsridharan.in
* Text Domain: woocommerce-quick-donation
......@@ -18,7 +18,7 @@ class WooCommerce_Quick_Donation {
/**
* @var string
*/
public $version = '1.3.2';
public $version = '1.3.3';
/**
* @var WooCommerce The single instance of the class
......@@ -64,6 +64,9 @@ class WooCommerce_Quick_Donation {
add_filter('load_textdomain_mofile', array( $this, 'load_plugin_mo_files' ), 10, 2);
}
/**
* Checks If Donation Product Exist In WooCommerce Products
*/
private function check_donation_product_exist(){
$install = new WC_QD_INSTALL;
if(! $install->check_donation_exists()){
......@@ -117,7 +120,7 @@ class WooCommerce_Quick_Donation {
self::$f = new WooCommerce_Quick_Donation_Functions;
self::$settings = new WooCommerce_Quick_Donation_Settings;
self::$db = new WooCommerce_Quick_Donation_db;
self::$db = new WooCommerce_Quick_Donation_DB;
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