Commit 61e0140e authored by Varun Sridharan's avatar Varun Sridharan

Issue Fixed And 1 Feature Added

* Fixed #56
* Fixed #52
* Added option get donate link using {wcqd_get_donate_link} function
* Minor bugfix and cleanup
parent 18dc04d8
...@@ -125,7 +125,12 @@ $fields['settings_shortcode']['shortcode'][] = array( ...@@ -125,7 +125,12 @@ $fields['settings_shortcode']['shortcode'][] = array(
'options' => WC_QD()->f()->get_porject_list(), 'options' => WC_QD()->f()->get_porject_list(),
'attr' => array('class' => 'wc-enhanced-select','style' => 'width:auto;max-width:35%;') 'attr' => array('class' => 'wc-enhanced-select','style' => 'width:auto;max-width:35%;')
); );
//WC_QD()->f()->get_porject_list()
?>
$fields['settings_shortcode']['shortcode'][] = array(
'id' => WC_QD_DB.'pre_defined_amount',
'type' => 'textarea',
'label' => __( 'Pre Defined Project Amount', WC_QD_TXT),
'desc' => __( 'Enter Donation Amount Like <code> 10|20|30|40 </code>',WC_QD_TXT),
'size ' => 'small',
'attr' => array('style' => 'min-width:35%; width:auto;max-width:75%;')
);
\ No newline at end of file
...@@ -4,5 +4,3 @@ global $pages; ...@@ -4,5 +4,3 @@ global $pages;
$pages[] = array('id'=>'settings_general','slug'=>'general','title'=>__('General',WC_QD_TXT)); $pages[] = array('id'=>'settings_general','slug'=>'general','title'=>__('General',WC_QD_TXT));
$pages[] = array('id'=>'settings_message','slug'=>'message','title'=>__('Message',WC_QD_TXT)); $pages[] = array('id'=>'settings_message','slug'=>'message','title'=>__('Message',WC_QD_TXT));
$pages[] = array('id'=>'settings_shortcode','slug'=>'shortcode','title'=>__('ShortCode',WC_QD_TXT)); $pages[] = array('id'=>'settings_shortcode','slug'=>'shortcode','title'=>__('ShortCode',WC_QD_TXT));
?>
\ No newline at end of file
...@@ -2,5 +2,4 @@ ...@@ -2,5 +2,4 @@
global $send_fields; global $send_fields;
if (empty($send_fields[WC_QD_DB.'payment_gateway'])) { if (empty($send_fields[WC_QD_DB.'payment_gateway'])) {
add_settings_error(WC_QD_DB.'payment_gateway','', __( 'Error: Please Select Atlest 1 Payment Gateway.', WC_QD_TXT ),'error'); add_settings_error(WC_QD_DB.'payment_gateway','', __( 'Error: Please Select Atlest 1 Payment Gateway.', WC_QD_TXT ),'error');
} }
?> \ No newline at end of file
\ No newline at end of file
<?php
global $send_fields;
?>
\ No newline at end of file
...@@ -8,6 +8,7 @@ class WC_QD_INSTALL{ ...@@ -8,6 +8,7 @@ class WC_QD_INSTALL{
public static function init(){ public static function init(){
$donation_exist = self::check_donation_exists(); $donation_exist = self::check_donation_exists();
self::check_db_version(); self::check_db_version();
self::post_register(); self::post_register();
self::wc_qd_table_install(); self::wc_qd_table_install();
self::check_template_files(); self::check_template_files();
...@@ -17,6 +18,8 @@ class WC_QD_INSTALL{ ...@@ -17,6 +18,8 @@ class WC_QD_INSTALL{
update_option(WC_QD_DB.'product_id',$post_id); update_option(WC_QD_DB.'product_id',$post_id);
} }
} }
/** /**
...@@ -26,6 +29,9 @@ class WC_QD_INSTALL{ ...@@ -26,6 +29,9 @@ class WC_QD_INSTALL{
WC_QD_Post_Types::register_donation_posttype(); WC_QD_Post_Types::register_donation_posttype();
WC_QD_Post_Types::register_donation_category(); WC_QD_Post_Types::register_donation_category();
WC_QD_Post_Types::register_donation_tags(); WC_QD_Post_Types::register_donation_tags();
add_rewrite_endpoint('donate-now', EP_ROOT);
flush_rewrite_rules(); flush_rewrite_rules();
} }
......
...@@ -69,13 +69,27 @@ class WooCommerce_Quick_Donation_Functions { ...@@ -69,13 +69,27 @@ class WooCommerce_Quick_Donation_Functions {
add_filter( 'woocommerce_locate_template' , array($this,'wc_locate_template'),10,3); add_filter( 'woocommerce_locate_template' , array($this,'wc_locate_template'),10,3);
add_filter( 'the_title', array($this,'wc_page_endpoint_title' ),10,2); add_filter( 'the_title', array($this,'wc_page_endpoint_title' ),10,2);
add_filter( 'wp_count_posts', array($this,'modify_wp_count_posts'),99,3); add_filter( 'wp_count_posts', array($this,'modify_wp_count_posts'),99,3);
add_filter( 'query_vars', array( $this, 'add_query_vars'), 0 );
} }
public function get_template_list(){ public function get_template_list(){
return self::$search_template; return self::$search_template;
} }
/**
* add_query_vars function.
*
* @access public
* @param array $vars
* @return array
*/
public function add_query_vars( $vars ) {
$vars[] = 'donate-now';
return $vars;
}
public function wc_page_endpoint_title($title = '', $id = ''){ public function wc_page_endpoint_title($title = '', $id = ''){
if(is_page($id)){ if(is_page($id)){
global $wp_query; global $wp_query;
...@@ -184,28 +198,50 @@ class WooCommerce_Quick_Donation_Functions { ...@@ -184,28 +198,50 @@ class WooCommerce_Quick_Donation_Functions {
} }
public function generate_price_box(){ public function generate_price_box($predefined = false){
global $id, $name, $class, $field_output,$attributes,$value; global $id, $name, $class, $field_output,$attributes,$value;
$type = 'text';
if($predefined){$type = 'select';}
$field_output = ''; $field_output = '';
$id = 'donation_price'; $id = 'donation_price';
$name = 'wc_qd_donate_project_price'; $name = 'wc_qd_donate_project_price';
$class = apply_filters('wcqd_project_price_text_class',array(),'text'); $class = apply_filters('wcqd_project_price_class',array(),$type);
$custom_attributes = apply_filters('wcqd_project_price_text_attribute',array(),'text'); $custom_attributes = apply_filters('wcqd_project_price_attribute',array(),$type);
$value = ''; $value = '';
$pre_amt = array();
$class = implode(' ',$class); $class = implode(' ',$class);
$attributes = ''; $attributes = '';
foreach($custom_attributes as $attr_key => $attr_val) { foreach($custom_attributes as $attr_key => $attr_val) {
$attributes .= $attr_key.'="'.$attr_val.'" '; $attributes .= $attr_key.'="'.$attr_val.'" ';
} }
if($predefined){
$field_output = $this->load_template('field-text.php',WC_QD_TEMPLATE . 'fields/' ,array('id' => $id, $amount = wcqd_get_option(WC_QD_DB.'pre_defined_amount');
$amount = explode('|',$amount);
$c = get_woocommerce_currency_symbol();
foreach($amount as $amts){
$pre_amt[$amts] = $c.''.$amts;
}
}
$project_list = $pre_amt;
$field_output = $this->load_template('field-'.$type.'.php', WC_QD_TEMPLATE.'fields/' , array('id' => $id,
'name' => $name,
'class' => $class,
'field_output' => $field_output,
'is_grouped' => false,
'project_list' => $project_list,
'pre_selected' => false,
'attributes' => $attributes,
'value' => $value));
/*$field_output = $this->load_template('field-text.php',WC_QD_TEMPLATE . 'fields/' ,array('id' => $id,
'name' => $name, 'name' => $name,
'class' => $class, 'class' => $class,
'field_output' => $field_output, 'field_output' => $field_output,
'attributes' => $attributes, 'attributes' => $attributes,
'value' => $value)); 'value' => $value)); */
return $field_output; return $field_output;
} }
...@@ -348,4 +384,41 @@ class WooCommerce_Quick_Donation_Functions { ...@@ -348,4 +384,41 @@ class WooCommerce_Quick_Donation_Functions {
wp_cache_set( $cache_key, $counts, 'wc_qd_modified_wp_count_posts' ); wp_cache_set( $cache_key, $counts, 'wc_qd_modified_wp_count_posts' );
return apply_filters( 'wc_qd_modified_wp_count_posts', $counts, $type, $perm ); return apply_filters( 'wc_qd_modified_wp_count_posts', $counts, $type, $perm );
} }
}
public function get_donate_link($donation_id='364',$amount = 10,$echo = false){
$data = array('donate' => true, 'id' =>$donation_id,'amount'=>$amount);
$url = $this->encryptor('encrypt', http_build_query($data));
$url = site_url().'/donate-now/'.$url;
if($echo){echo $url; return;}
return $url;
}
public function encryptor($action, $string) {
$output = false;
$encrypt_method = "AES-256-CBC";
//pls set your unique hashing key
$secret_key = 'muni';
$secret_iv = 'muni123';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
//do the encyption given text/string/number
if( $action == 'encrypt' ) {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
}
else if( $action == 'decrypt' ){
//decrypt the given text/string/number
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}
return $output;
}
}
\ No newline at end of file
...@@ -12,11 +12,23 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation { ...@@ -12,11 +12,23 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
function __construct(){ function __construct(){
parent::__construct(); parent::__construct();
add_action( 'woocommerce_checkout_update_order_meta',array($this,'save_order_id_db'),1); add_action( 'woocommerce_checkout_update_order_meta',array($this,'save_order_id_db'),1);
add_action( 'pre_get_posts', array( $this, 'add_doantion_via_link' ) );
add_action( 'wp_loaded',array($this,'on_wp_loaded'),20); add_action( 'wp_loaded',array($this,'on_wp_loaded'),20);
add_filter( 'woocommerce_get_price', array($this,'get_price'),10,2); add_filter( 'woocommerce_get_price', array($this,'get_price'),10,2);
} }
public function add_doantion_via_link($wp_query){
if(isset($wp_query->query_vars['donate-now'])){
$get_string = WC_QD()->f()->encryptor('decrypt', $wp_query->query_vars['donate-now']);
parse_str($get_string, $get_array);
$this->process_donation(true,$get_array['id'],$get_array['amount']);
exit;
}
return $wp_query;
}
public function on_wp_loaded(){ public function on_wp_loaded(){
if($this->check_donation_exists_cart()){ if($this->check_donation_exists_cart()){
$this->is_donation_exists = true; $this->is_donation_exists = true;
...@@ -74,10 +86,10 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation { ...@@ -74,10 +86,10 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
} }
public function process_donation(){ public function process_donation($donate_add = false,$project_id = null,$amount=null){
if(isset($_POST['donation_add'])){ if(isset($_POST['donation_add']) || $donate_add === true){
if($this->check_donation_already_exist()){ if($this->check_donation_already_exist()){
$message = WC_QD()->db()->get_message(WC_QD_DB.'donation_already_exist'); $message = WC_QD()->db()->get_message(WC_QD_DB.'donation_already_exist');
wc_add_notice($message,'error'); wc_add_notice($message,'error');
...@@ -92,8 +104,8 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation { ...@@ -92,8 +104,8 @@ class WooCommerce_Quick_Donation_Process extends WooCommerce_Quick_Donation {
} }
global $woocommerce; global $woocommerce;
$donateprice = isset($_POST['wc_qd_donate_project_price']) ? $_POST['wc_qd_donate_project_price'] : false; $donateprice = isset($_POST['wc_qd_donate_project_price']) ? $_POST['wc_qd_donate_project_price'] : $amount;
$projects = isset($_POST['wc_qd_donate_project_name']) && !empty($_POST['wc_qd_donate_project_name']) ? $_POST['wc_qd_donate_project_name'] : false; $projects = isset($_POST['wc_qd_donate_project_name']) && !empty($_POST['wc_qd_donate_project_name']) ? $_POST['wc_qd_donate_project_name'] : $project_id;
$check_donation_price = $this->check_donation_price_status($donateprice); $check_donation_price = $this->check_donation_price_status($donateprice);
if( ! $check_donation_price){return false;} if( ! $check_donation_price){return false;}
......
<?php <?php
/** /**
* functionality of the plugin. * functionality of the plugin.
*
* @link @TODO * @link @TODO
* @since 1.0 * @since 1.0
*
* @package @TODO
* @subpackage @TODO
*
* @package @TODO * @package @TODO
* @subpackage @TODO * @subpackage @TODO
* @author Varun Sridharan <varunsridharan23@gmail.com> * @author Varun Sridharan <varunsridharan23@gmail.com>
...@@ -29,10 +24,12 @@ class WooCommerce_Quick_Donation_Shortcode { ...@@ -29,10 +24,12 @@ class WooCommerce_Quick_Donation_Shortcode {
'grouped' => false, 'grouped' => false,
'show_errors' => wcqd_get_option(WC_QD_DB.'shortcode_show_errors'), 'show_errors' => wcqd_get_option(WC_QD_DB.'shortcode_show_errors'),
'selected_value' => wcqd_get_option(WC_QD_DB.'pre_selected_project'), 'selected_value' => wcqd_get_option(WC_QD_DB.'pre_selected_project'),
'defined_amount' => false
), $settings ); ), $settings );
$donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type'],$settings['selected_value']); $donation_box = WC_QD()->f()->generate_donation_selbox($settings['grouped'],$settings['type'],$settings['selected_value']);
$donation_price = WC_QD()->f()->generate_price_box(); $donation_price = WC_QD()->f()->generate_price_box($settings['defined_amount']);
$currency = get_woocommerce_currency_symbol(); $currency = get_woocommerce_currency_symbol();
$return_value = ''; $return_value = '';
$messages = ''; $messages = '';
...@@ -44,15 +41,14 @@ class WooCommerce_Quick_Donation_Shortcode { ...@@ -44,15 +41,14 @@ class WooCommerce_Quick_Donation_Shortcode {
ob_flush(); ob_flush();
} }
// ob_start();
do_action('wc_quick_donation_before_doantion_form',$return_value , $settings['type'],$settings['grouped']); do_action('wc_quick_donation_before_doantion_form',$return_value , $settings['type'],$settings['grouped']);
$messages .= WC_QD()->f()->load_template('donation-form.php',WC_QD_TEMPLATE,array('donation_box' => $donation_box, $messages .= WC_QD()->f()->load_template('donation-form.php',WC_QD_TEMPLATE,array('donation_box' => $donation_box,
'donation_price' => $donation_price, 'donation_price' => $donation_price,
'currency' => $currency)); 'currency' => $currency));
do_action('wc_quick_donation_after_doantion_form',$return_value , $settings['type'],$settings['grouped']); do_action('wc_quick_donation_after_doantion_form',$return_value , $settings['type'],$settings['grouped']);
//$messages .= ob_get_clean();
return $messages;
return $messages;
} }
} }
\ No newline at end of file
...@@ -86,5 +86,14 @@ if(! function_exists('wcqd_get_option')){ ...@@ -86,5 +86,14 @@ if(! function_exists('wcqd_get_option')){
} }
} }
if(! function_exists('wcqd_get_donate_link')){
function wcqd_get_donate_link($donation_id='364',$amount = 10,$echo = false){
$link = WC_QD()->f()->get_donate_link($donation_id,$amount,false);
if($echo){ echo $link; return; }
return $link;
}
}
?> ?>
\ 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