Commit b8063aa9 authored by Varun Sridharan's avatar Varun Sridharan

Updated Class

[admin/class-admin-init.php]
* Added woocommerce_screen_ids
* Removed Admin Notice Handler Class Init
* Added Plugins Settings Page ID To WC Screen ID

[admin/class-admin-settings.php & admin/class-donation-settings.php]
* Working To Get A Prefect Settings Page

[admin/includes/class-admin-functions.php]
* Changed WC_QD()->donation_id to WC_QD_ID

[includes/class-quick-donation-process.php]
* Created Class To Process Front End Donation Form

[includes/class-shortcode-handler.php]
* Created 2 Actions
1. wc_quick_donation_before_donation_form
2. wc_quick_donation_after_donation_form

[woocommerce-quick-donation.php]
* Changed $donation_id from dynimic to static
* Added WC_QD_ID defined variable
* Rearranged Few Loading Files
parent c7f74212
...@@ -28,17 +28,19 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -28,17 +28,19 @@ class WooCommerce_Quick_Donation_Admin {
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'admin_init', array( $this, 'init_admin_class' )); add_action( 'admin_init', array( $this, 'init_admin_class' ));
add_action( 'plugins_loaded', array( $this, 'init' ) ); add_action( 'plugins_loaded', array( $this, 'init' ) );
add_filter( 'plugin_row_meta', array($this, 'plugin_row_links' ), 10, 2 ); add_filter( 'plugin_row_meta', array($this, 'plugin_row_links' ), 10, 2 );
add_filter( 'woocommerce_get_settings_pages', array($this,'settings_page') );
add_filter('woocommerce_screen_ids',array($this,'set_wc_screen_ids'));
} }
/** /**
* Inits Admin Sttings * Inits Admin Sttings
*/ */
public function init_admin_class(){ public function init_admin_class(){
$this->functions = new WooCommerce_Quick_Donation_Admin_Function; $this->functions = new WooCommerce_Quick_Donation_Admin_Function;
//$this->notice = new WordPress_Admin_Notice_Handler;
# new WooCommerce_Plugin_Boiler_Plate_Admin_Settings; # new WooCommerce_Plugin_Boiler_Plate_Admin_Settings;
} }
...@@ -73,6 +75,13 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -73,6 +75,13 @@ class WooCommerce_Quick_Donation_Admin {
} }
public function set_wc_screen_ids($screen){
$screen[] = 'wcqd_project_page_wc_qd_settings';
return $screen;
}
/** /**
* Gets Current Screen ID from wordpress * Gets Current Screen ID from wordpress
* @return string [Current Screen ID] * @return string [Current Screen ID]
...@@ -90,6 +99,7 @@ class WooCommerce_Quick_Donation_Admin { ...@@ -90,6 +99,7 @@ class WooCommerce_Quick_Donation_Admin {
$screen_ids = array(); $screen_ids = array();
$screen_ids[] = 'edit-product'; $screen_ids[] = 'edit-product';
$screen_ids[] = 'product'; $screen_ids[] = 'product';
$screen_ids[] = 'wcqd_project_page_wc_qd_settings';
return $screen_ids; return $screen_ids;
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -33,10 +33,7 @@ class WooCommerce_Quick_Donation_Admin_Function { ...@@ -33,10 +33,7 @@ class WooCommerce_Quick_Donation_Admin_Function {
public function protect_donation_product($actions,$post) { public function protect_donation_product($actions,$post) {
if('product' == $post->post_type) { if('product' == $post->post_type) {
if($post->ID == WC_QD_ID){
if($post->ID == WC_QD()->donation_id){
unset($actions['inline hide-if-no-js']); unset($actions['inline hide-if-no-js']);
unset($actions['trash']); unset($actions['trash']);
unset($actions['duplicate']); unset($actions['duplicate']);
......
<?php
/**
* functionality of the plugin.
* @author Varun Sridharan <varunsridharan23@gmail.com>
*/
if ( ! defined( 'WPINC' ) ) { die; }
class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
public $is_donation_exists = false;
function __construct(){
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(){
if($this->check_donation_exists_cart()){ $this->is_donation_exists = true; }
$this->process_donation();
}
public function process_donation(){
if(isset($_POST['donation_add'])){
global $woocommerce;
$donation = 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;
$donate_price = floatval($donation);
$woocommerce->session->jc_donation = $donate_price;
$woocommerce->session->projects = $projects;
$woocommerce->cart->add_to_cart(self::$donation_id);
}
}
/**
* Checks If Donation Product Exists In Cart
*/
public function check_donation_exists_cart(){
global $woocommerce;
$found = false;
if( sizeof($woocommerce->cart->get_cart()) > 0){
foreach($woocommerce->cart->get_cart() as $cart_item_key=>$values){
$_product = $values['data'];
if($_product->id == self::$donation_id)
$found = true;
}
}
return $found;
}
/**
* Gets Donation Current Price
* @param $price
* @param $product
* @returns 0 | price
*/
public function get_price($price, $product){
global $woocommerce;
if($this->is_donation_exists){
if($product->id == self::$donation_id){
return isset($woocommerce->session->jc_donation) ? floatval($woocommerce->session->jc_donation) : 0;
}
}
return $price;
}
}
\ No newline at end of file
...@@ -24,14 +24,16 @@ class WooCommerce_Quick_Donation_Shortcode { ...@@ -24,14 +24,16 @@ class WooCommerce_Quick_Donation_Shortcode {
public function shortcode_handler($settings){ public function shortcode_handler($settings){
global $donation_box,$donation_price,$currency; global $donation_box,$donation_price,$currency;
$settings = shortcode_atts( array( $settings = shortcode_atts( array(
'type' => 'radio', 'type' => 'select',
'grouped' => true, 'grouped' => false,
), $settings ); ), $settings );
$donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type']); $donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type']);
$donation_price = WC_QD()->f()->generate_price_box(); $donation_price = WC_QD()->f()->generate_price_box();
$currency = get_woocommerce_currency_symbol(); $currency = get_woocommerce_currency_symbol();
do_action('wc_quick_donation_before_doantion_form',$settings['type'],$settings['grouped']);
WC_QD()->f()->load_template('donation_form.php',WC_QD_TEMPLATE); WC_QD()->f()->load_template('donation_form.php',WC_QD_TEMPLATE);
do_action('wc_quick_donation_after_doantion_form',$settings['type'],$settings['grouped']);
} }
} }
\ No newline at end of file
...@@ -28,7 +28,7 @@ class WooCommerce_Quick_Donation { ...@@ -28,7 +28,7 @@ class WooCommerce_Quick_Donation {
public static $is_donation_product_exist = true; public static $is_donation_product_exist = true;
protected static $f = null; protected static $f = null;
public static $shortcode = null; public static $shortcode = null;
public $donation_id = null; public static $donation_id = null;
/** /**
* Creates or returns an instance of this class. * Creates or returns an instance of this class.
...@@ -45,7 +45,10 @@ class WooCommerce_Quick_Donation { ...@@ -45,7 +45,10 @@ class WooCommerce_Quick_Donation {
*/ */
public function __construct() { public function __construct() {
$this->define_constant(); $this->define_constant();
$this->donation_id = get_option(WC_QD_DB.'product_id'); self::$donation_id = get_option(WC_QD_DB.'product_id');
$this->define('WC_QD_ID',intval(get_option(WC_QD_DB.'product_id')));
$this->load_required_files(); $this->load_required_files();
register_activation_hook( __FILE__,array('WC_QD_INSTALL','INIT') ); register_activation_hook( __FILE__,array('WC_QD_INSTALL','INIT') );
...@@ -79,7 +82,9 @@ class WooCommerce_Quick_Donation { ...@@ -79,7 +82,9 @@ class WooCommerce_Quick_Donation {
$this->load_files(WC_QD_PATH.'includes/class-install.php'); $this->load_files(WC_QD_PATH.'includes/class-install.php');
$this->load_files(WC_QD_PATH.'includes/class-quick-donation-functions.php'); $this->load_files(WC_QD_PATH.'includes/class-quick-donation-functions.php');
$this->load_files(WC_QD_PATH.'includes/class-quick-donation-process.php');
$this->load_files(WC_QD_PATH.'includes/class-shortcode-handler.php'); $this->load_files(WC_QD_PATH.'includes/class-shortcode-handler.php');
if($this->is_request('admin')){ if($this->is_request('admin')){
$this->load_files(WC_QD_PATH.'admin/class-*.php'); $this->load_files(WC_QD_PATH.'admin/class-*.php');
} }
...@@ -92,6 +97,7 @@ class WooCommerce_Quick_Donation { ...@@ -92,6 +97,7 @@ class WooCommerce_Quick_Donation {
private function init_class(){ private function init_class(){
self::$f = new WooCommerce_Quick_Donation_Functions; self::$f = new WooCommerce_Quick_Donation_Functions;
self::$shortcode = new WooCommerce_Quick_Donation_Shortcode; self::$shortcode = new WooCommerce_Quick_Donation_Shortcode;
$this->donation = new WooCommerce_Quick_Donation_Process;
if($this->is_request('admin')){ if($this->is_request('admin')){
$this->admin = new WooCommerce_Quick_Donation_Admin; $this->admin = new WooCommerce_Quick_Donation_Admin;
......
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