Commit dd7a3bbb authored by Varun Sridharan's avatar Varun Sridharan

Minor Fix

Changed Order Text To Donation in Order Details Metabox
Loaded Admin Notice Before
Registered Custom Post Status [#27]
Checked If WooCommerce Is Active [#23]
parent 2293b1da
...@@ -189,17 +189,17 @@ class WC_Quick_Donation_Meta_Box_Order_Data { ...@@ -189,17 +189,17 @@ class WC_Quick_Donation_Meta_Box_Order_Data {
<div class="order_data_column_container"> <div class="order_data_column_container">
<div class="order_data_column"> <div class="order_data_column">
<h4><?php _e( 'General Details', 'woocommerce' ); ?></h4> <h4><?php _e( 'Donation Details', WC_QD_TXT ); ?></h4>
<p class="form-field form-field-wide"><label for="order_date"><?php _e( 'Order date:', 'woocommerce' ) ?></label> <p class="form-field form-field-wide"><label for="order_date"><?php _e( 'Donation date:', WC_QD_TXT ) ?></label>
<input type="hidden" name="post_is_donation" value="TRUE"/> <input type="hidden" name="post_is_donation" value="TRUE"/>
<input type="text" class="date-picker" name="order_date" id="order_date" maxlength="10" value="<?php echo date_i18n( 'Y-m-d', strtotime( $post->post_date ) ); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />@<input type="text" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ) ?>" name="order_date_hour" id="order_date_hour" maxlength="2" size="2" value="<?php echo date_i18n( 'H', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" />:<input type="text" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ) ?>" name="order_date_minute" id="order_date_minute" maxlength="2" size="2" value="<?php echo date_i18n( 'i', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" /> <input type="text" class="date-picker" name="order_date" id="order_date" maxlength="10" value="<?php echo date_i18n( 'Y-m-d', strtotime( $post->post_date ) ); ?>" pattern="[0-9]{4}-(0[1-9]|1[012])-(0[1-9]|1[0-9]|2[0-9]|3[01])" />@<input type="text" class="hour" placeholder="<?php esc_attr_e( 'h', 'woocommerce' ) ?>" name="order_date_hour" id="order_date_hour" maxlength="2" size="2" value="<?php echo date_i18n( 'H', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" />:<input type="text" class="minute" placeholder="<?php esc_attr_e( 'm', 'woocommerce' ) ?>" name="order_date_minute" id="order_date_minute" maxlength="2" size="2" value="<?php echo date_i18n( 'i', strtotime( $post->post_date ) ); ?>" pattern="\-?\d+(\.\d{0,})?" />
</p> </p>
<p class="form-field form-field-wide"><label for="order_status"><?php _e( 'Order status:', 'woocommerce' ) ?></label> <p class="form-field form-field-wide"><label for="order_status"><?php _e( 'Donation status:', WC_QD_TXT ) ?></label>
<select id="order_status" name="order_status" class="wc-enhanced-select"> <select id="order_status" name="order_status" class="wc-enhanced-select">
<?php <?php
$statuses = wc_get_order_statuses(); $statuses = wc_qd_order_statuses();
foreach ( $statuses as $status => $status_name ) { foreach ( $statuses as $status => $status_name ) {
echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status(), false ) . '>' . esc_html( $status_name ) . '</option>'; echo '<option value="' . esc_attr( $status ) . '" ' . selected( $status, 'wc-' . $order->get_status(), false ) . '>' . esc_html( $status_name ) . '</option>';
} }
......
...@@ -30,9 +30,9 @@ if ( ! defined( 'ABSPATH' ) ) { ...@@ -30,9 +30,9 @@ if ( ! defined( 'ABSPATH' ) ) {
die( 'Access denied.' ); die( 'Access denied.' );
} }
if ( ! class_exists( 'Admin_Notice_Helper' ) ) { if ( ! class_exists( 'WC_QD_Admin_Notice_Helper' ) ) {
class Admin_Notice_Helper { class WC_QD_Admin_Notice_Helper {
// Declare variables and constants // Declare variables and constants
protected static $instance; protected static $instance;
protected $notices, $notices_were_updated; protected $notices, $notices_were_updated;
...@@ -42,7 +42,7 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) { ...@@ -42,7 +42,7 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) {
*/ */
protected function __construct() { protected function __construct() {
$this->init(); $this->init();
//add_action( 'init', array( $this, 'init' )); // needs to run before other plugin's init callbacks so that they can enqueue messages in their init callbacks //add_action( 'init', array( $this, 'init' )); // needs to run before other plugin's init callbacks so that they can enqueue messages in their init callbacks
add_action( 'admin_notices', array( $this, 'print_notices' ) ); add_action( 'admin_notices', array( $this, 'print_notices' ) );
add_action( 'shutdown', array( $this, 'shutdown' ) ); add_action( 'shutdown', array( $this, 'shutdown' ) );
} }
...@@ -56,7 +56,7 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) { ...@@ -56,7 +56,7 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) {
*/ */
public static function get_singleton() { public static function get_singleton() {
if ( ! isset( self::$instance ) ) { if ( ! isset( self::$instance ) ) {
self::$instance = new Admin_Notice_Helper(); self::$instance = new WC_QD_Admin_Notice_Helper();
} }
return self::$instance; return self::$instance;
...@@ -67,7 +67,6 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) { ...@@ -67,7 +67,6 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) {
*/ */
public function init() { public function init() {
$default_notices = array( 'update' => array(), 'error' => array() ); $default_notices = array( 'update' => array(), 'error' => array() );
$this->notices = array_merge( $default_notices, get_option( 'anh_notices', array() ) ); $this->notices = array_merge( $default_notices, get_option( 'anh_notices', array() ) );
$this->notices_were_updated = false; $this->notices_were_updated = false;
} }
...@@ -96,9 +95,9 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) { ...@@ -96,9 +95,9 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) {
* Displays updates and errors * Displays updates and errors
*/ */
public function print_notices() { public function print_notices() {
//$this->notices_were_updated = true;
foreach ( array( 'update', 'error' ) as $type ) { foreach ( array( 'update', 'error' ) as $type ) {
if ( count( $this->notices[ $type ] ) ) { if ( count( $this->notices[ $type ] ) ) {
$class = 'update' == $type ? 'updated' : 'error'; $class = 'update' == $type ? 'updated' : 'error';
...@@ -129,11 +128,11 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) { ...@@ -129,11 +128,11 @@ if ( ! class_exists( 'Admin_Notice_Helper' ) ) {
} }
} // end Admin_Notice_Helper } // end Admin_Notice_Helper
Admin_Notice_Helper::get_singleton(); // Create the instance immediately to make sure hook callbacks are registered in time WC_QD_Admin_Notice_Helper::get_singleton(); // Create the instance immediately to make sure hook callbacks are registered in time
if ( ! function_exists( 'wc_qd_notice' ) ) { if ( ! function_exists( 'wc_qd_notice' ) ) {
function wc_qd_notice( $message, $type = 'update' ) { function wc_qd_notice( $message, $type = 'update' ) {
Admin_Notice_Helper::get_singleton()->enqueue( $message, $type ); WC_QD_Admin_Notice_Helper::get_singleton()->enqueue( $message, $type );
} }
} }
} }
......
...@@ -7,9 +7,10 @@ class WC_QD_Post_Types { ...@@ -7,9 +7,10 @@ class WC_QD_Post_Types {
* Inits Post Types Class * Inits Post Types Class
*/ */
public static function init(){ public static function init(){
add_action( 'init', array(__CLASS__,'register_donation_posttype'),5); 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_category'), 5 );
add_action( 'init', array(__CLASS__,'register_donation_tags' ), 5 ); add_action( 'init', array(__CLASS__,'register_donation_tags' ), 5 );
add_action( 'init', array(__CLASS__,'register_post_status' ), 0 );
} }
/** /**
...@@ -167,6 +168,35 @@ class WC_QD_Post_Types { ...@@ -167,6 +168,35 @@ class WC_QD_Post_Types {
register_taxonomy( 'wcqd_tags', array(WC_QD_PT ), $args ); register_taxonomy( 'wcqd_tags', array(WC_QD_PT ), $args );
} }
// Register Custom Status
public static function register_post_status() {
register_post_status( 'donation-completed', array(
'label' => _x( 'Completed', 'Order status',WC_QD_TXT),
'label_count' => _n_noop( 'Completed (%s)', 'Completed (%s)', WC_QD_TXT),
'public' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'exclude_from_search' => true,
) );
register_post_status( 'donation-on-hold', array(
'label' => _x( 'Donation On Hold', 'Order status', WC_QD_TXT),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Donation On Hold <span class="count">(%s)</span>', 'DonationOn Hold <span class="count">(%s)</span>',WC_QD_TXT)
) );
register_post_status( 'donation-refunded', array(
'label' => _x( 'Donation Refunded', 'Order status', WC_QD_TXT),
'public' => false,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', WC_QD_TXT)
) );
}
} }
......
<?php
/**
* WC Dependency Checker
*
* Checks if WooCommerce is enabled
*/
if ( ! class_exists( 'WC_QD_Dependencies' ) ){
class WC_QD_Dependencies {
private static $active_plugins;
public static function init() {
self::$active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() )
self::$active_plugins = array_merge( self::$active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
}
public static function woocommerce_active_check() {
if ( ! self::$active_plugins ) self::init();
return in_array('woocommerce/woocommerce.php', self::$active_plugins) || array_key_exists('woocommerce/woocommerce.php', self::$active_plugins);
}
}
}
/**
* WC Detection
*/
if(! function_exists('is_wc_qd_dependencies_active')){
function WC_QD_Dependencies() {
return WC_QD_Dependencies::woocommerce_active_check();
}
}
?>
\ No newline at end of file
...@@ -8,7 +8,7 @@ if(! function_exists('qd_get_message')){ ...@@ -8,7 +8,7 @@ if(! function_exists('qd_get_message')){
} }
if(! function_exists('qd_min_amount_project'){ if(! function_exists('qd_min_amount_project')){
function qd_min_amount_project($id = ''){ function qd_min_amount_project($id = ''){
$min = WC_QD()->db()->min_project($id); $min = WC_QD()->db()->min_project($id);
return $min; return $min;
...@@ -16,10 +16,26 @@ if(! function_exists('qd_min_amount_project'){ ...@@ -16,10 +16,26 @@ if(! function_exists('qd_min_amount_project'){
} }
if(! function_exists('qd_max_amount_project'){ if(! function_exists('qd_max_amount_project')){
function qd_max_amount_project($id = ''){ function qd_max_amount_project($id = ''){
$max = WC_QD()->db()->max_project($id); $max = WC_QD()->db()->max_project($id);
return $max; return $max;
} }
} }
/**
* Get all order statuses
*
* @since 2.2
* @return array
*/
function wc_qd_order_statuses() {
$wc_status = wc_get_order_statuses();
$order_statuses = array();
$order_statuses['donation-completed'] = _x( 'Donation Completed', 'Donation Completed', WC_QD_TXT );
$order_statuses['donation-refunded'] = _x( 'Donation Refunded', 'Order status', WC_QD_TXT);
$order_statuses['donation-on-hold'] = _x( 'Donation On Hold', 'Order status', WC_QD_TXT);
$order_statuses = array_merge($order_statuses,$wc_status);
return $order_statuses;
}
?> ?>
\ No newline at end of file
...@@ -95,6 +95,7 @@ class WooCommerce_Quick_Donation { ...@@ -95,6 +95,7 @@ class WooCommerce_Quick_Donation {
* Loads Required Plugins For Plugin * Loads Required Plugins For Plugin
*/ */
private function load_required_files(){ private function load_required_files(){
$this->load_files(WC_QD_INC.'wc-quick-donation-*.php');
$this->load_files(WC_QD_ADMIN.'wps/*.php'); $this->load_files(WC_QD_ADMIN.'wps/*.php');
$this->load_files(WC_QD_INC.'class-admin-notice.php'); $this->load_files(WC_QD_INC.'class-admin-notice.php');
$this->load_files(WC_QD_INC.'class-post-*.php'); $this->load_files(WC_QD_INC.'class-post-*.php');
...@@ -273,10 +274,17 @@ class WooCommerce_Quick_Donation { ...@@ -273,10 +274,17 @@ class WooCommerce_Quick_Donation {
} }
function WC_QD(){ require_once(plugin_dir_path(__FILE__).'includes/class-wc-dependencies.php');
return WooCommerce_Quick_Donation::get_instance(); require_once(plugin_dir_path(__FILE__).'includes/class-admin-notice.php');
}
if(WC_QD_Dependencies()){
function WC_QD(){
return WooCommerce_Quick_Donation::get_instance();
}
$GLOBALS['woocommerce_quick_donation'] = WC_QD(); $GLOBALS['woocommerce_quick_donation'] = WC_QD();
} else {
wc_qd_notice('WooCommerce Is Required. To Use This Plugin :)','error');
}
?> ?>
\ 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