woocommerce-quick-donation-settings.php 9.78 KB
Newer Older
Tech No Freaky's avatar
Tech No Freaky committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
<?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
Tech No Freaky's avatar
Tech No Freaky committed
29
     */
Tech No Freaky's avatar
Tech No Freaky committed
30 31
    public function get_sections() {
        $sections = array(
Tech No Freaky's avatar
Tech No Freaky committed
32 33 34
            'general' => __( 'General Settings', $this->id ),
            'donation' => __( 'Donation Settings', $this->id ),
            'message' => __( 'Message Settings', $this->id )
Tech No Freaky's avatar
Tech No Freaky committed
35 36 37 38 39
             
        );

        return apply_filters( 'woocommerce_get_sections_' . $this->id, $sections );
    }
Tech No Freaky's avatar
Tech No Freaky committed
40

Tech No Freaky's avatar
Tech No Freaky committed
41 42 43 44 45 46 47

    /**
     * Get sections
     *
     * @return array
     */
    public function get_settings( $section = null ) {
Tech No Freaky's avatar
Tech No Freaky committed
48 49 50
		global $wc_quick_donation;
        $width = "width:50% !important;";

Tech No Freaky's avatar
Tech No Freaky committed
51 52 53 54 55 56 57 58 59 60 61
        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.
						',
Tech No Freaky's avatar
Tech No Freaky committed
62
						'id' => 'wc_quick_donation_general_start'
Tech No Freaky's avatar
Tech No Freaky committed
63 64 65 66 67 68 69 70
					), 			

					'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',
Tech No Freaky's avatar
Tech No Freaky committed
71
                        'css'     => $width,
Tech No Freaky's avatar
Tech No Freaky committed
72 73 74 75 76 77 78 79 80 81
						'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',
Tech No Freaky's avatar
Tech No Freaky committed
82
                        'css'     => $width,
Tech No Freaky's avatar
Tech No Freaky committed
83 84 85 86 87 88 89 90 91 92
						'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',
Tech No Freaky's avatar
Tech No Freaky committed
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
                        'css'     => $width,
						'options' => $wc_quick_donation->get_payments_gateway()
					), 				
					'section_end' => array(
						'type' => 'sectionend',
						'id' => 'wc_quick_donation_general_end'
					)
				);
            break;
            case 'donation' :
                $settings = array(
					'section_title' => array(
						'name' => 'Donation Releated Settings',
						'type' => 'title',
						'desc' => '',
						'id' => 'wc_quick_donation_donation_start'
					), 	
Tech No Freaky's avatar
Tech No Freaky committed
110 111 112
					'project_names' => array(
						'name' => 'Project Names',
						'type' => 'textarea',
Tech No Freaky's avatar
Tech No Freaky committed
113 114 115
						'desc_tip' => 'Add Names By <code>,</code> Seperated ',
                        'css'     => 'width:50%; height: 105px;',
                        'std'     => '', // for woocommerce < 2.0 
Tech No Freaky's avatar
Tech No Freaky committed
116
						'id' => 'wc_quick_donation_projects', 
Tech No Freaky's avatar
Tech No Freaky committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
						'default' => 'Project1,Project2'  // for woocommerce >= 2.0

					),
                    'min_required_donation' => array(
						'name' => 'Minium Required Amount',
						'type' => 'text',
						'desc' => 'Minium Required Amount For Donation. Enter Only Numerical Eg : 100', 
						'id' => 'wc_quick_donation_min_required_donation', 
						'default' =>'50'

					),
                    'max_required_donation' => array(
						'name' => 'Maximum Allowed Amount',
						'type' => 'text',
						'desc' => 'Maximum Allowed Amount For Donation. Enter Only Numerical Eg : 1000', 
						'id' => 'wc_quick_donation_max_required_donation', 
						'default' =>'1000'
Tech No Freaky's avatar
Tech No Freaky committed
134 135 136 137 138

					),
					'order_project_title' => array(
						'name' => 'Order Project Title',
						'type' => 'text',
Tech No Freaky's avatar
Tech No Freaky committed
139 140
						'desc_tip' => 'Title to view in order edit page',
                        'css'     => $width,
Tech No Freaky's avatar
Tech No Freaky committed
141 142 143 144 145 146 147
						'id' => 'wc_quick_donation_project_section_title', 
						'default' =>'For Project'

					),
					'order_notes_title' => array(
						'name' => 'Order Notes Title',
						'type' => 'text',
Tech No Freaky's avatar
Tech No Freaky committed
148 149 150
						'desc_tip' => 'to display project name use <code>Project Name : %s</code>',
						'id' => 'wc_quick_donation_order_notes_title',
                         'css'     => $width,
Tech No Freaky's avatar
Tech No Freaky committed
151 152
						'default' =>'Project Name %s'

Tech No Freaky's avatar
Tech No Freaky committed
153
					),					
Tech No Freaky's avatar
Tech No Freaky committed
154 155
					'section_end' => array(
						'type' => 'sectionend',
Tech No Freaky's avatar
Tech No Freaky committed
156
						'id' => 'wc_quick_donation_donation_end'
Tech No Freaky's avatar
Tech No Freaky committed
157
					)
Tech No Freaky's avatar
Tech No Freaky committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
				);            
                
            break;
            case 'message' : 
                $settings = array(
                        'section_title' => array(
                            'name' => 'Plugin Message Text',
                            'type' => 'title',
                            'desc' => '',
                            'id' => 'wc_quick_donation_message_start'
                        ), 	
                        'project_invalid_message' => array(
                            'name' => 'Invalid / No Project Selected',
                            'type' => 'textarea',
                            'desc_tip' => 'Message Displayed When No Project Is Selected | HTML Tags Allowed',
                            'css' => 'width:75%; height:75px;',
                            'id' => 'wc_quick_donation_msg_project_invalid', 
                            'default' =>'<h2> No Project Selected </h2>'
                        ), 
                        'donation_amount_empty_message' => array(
                            'name' => 'Empty Donation Amount',
                            'type' => 'textarea',
                            'desc_tip' => 'Message Displayed When No Donation Entered | HTML Tags Allowed', 
                            'css' => 'width:75%; height:75px;',
                            'id' => 'wc_quick_donation_msg_amount_empty', 
                            'default' =>'<h2> Please Enter A Donation Amount </h2>'
                        ), 
                        'donation_amount_invalid_message' => array(
                            'name' => 'Invalid Donation Amount',
                            'type' => 'textarea',
                            'desc_tip' => 'Message Displayed When Invalid Donation Entered | HTML Tags Allowed',
                            'desc' => 'Add <code>{donation_amount}</code> For Entered Donation Amount',
                            'css' => 'width:75%; height:75px;',
                            'id' => 'wc_quick_donation_msg_amount_invalid', 
                            'default' =>'<h2> Invalid Donation Amount [{donation_amount}]  </h2>'
                        ),  
                        'donation_min_required' => array(
                            'name' => 'Minium Required Donation Amount',
                            'type' => 'textarea',
                            'desc_tip' => 'Message Displayed When Donation Amount Is Less than required amount | HTML Tags Allowed',
                            'desc' => 'Add <code>{donation_amount}</code> For Entered Donation Amount And Add <code>{min_amount}</code> For Minium Required Amount ',
                            'css' => 'width:75%; height:75px;',
                            'id' => 'wc_quick_donation_msg_amount_min_required', 
                            'default' =>'<h2> Minium Required is {min_amount} And you have entered is {donation_amount}  </h2>'
                        ), 
                    
                        'donation_max_allowed' => array(
                            'name' => 'Maximum Allowed Donation Amount',
                            'type' => 'textarea',
                            'desc_tip' => 'Message Displayed When Donation Amount Is Greater than allowed amount | HTML Tags Allowed',
                            'desc' => 'Add <code>{donation_amount}</code> For Entered Donation Amount And Add <code>{max_amount}</code> For Maximum Allowed Amount ',
                            'css' => 'width:75%; height:75px;',
                            'id' => 'wc_quick_donation_msg_amount_max_allowed', 
                            'default' =>'<h2> Maximum Allowed Is {max_amount} And you have entered is {donation_amount}  </h2>'
                        ), 
                    
                    
                        'section_end' => array(
                            'type' => 'sectionend',
                            'id' => 'wc_quick_donation_message_end'
                        )
                    );            

Tech No Freaky's avatar
Tech No Freaky committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
            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();

?>