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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 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 221 222 223 224 225 226 227 228
<?php
class DFW_Deposits_Settings {
public function __construct(){
add_filter( 'woocommerce_get_sections_products' , array( &$this, 'dfw_add_settings_tab' ), 10 );
add_filter( 'woocommerce_get_settings_products' , array( &$this, 'dfw_get_settings' ), 10, 2 );
add_action( 'woocommerce_admin_field_button' , array( &$this, 'dfw_add_admin_field_button' ) );
}
public function dfw_add_admin_field_button( $value ){
$option_value = (array) WC_Admin_Settings::get_option( $value['id'] );
$description = WC_Admin_Settings::get_field_description( $value );
$license = get_option( 'dfw_edd_license_key' );
$status = get_option( 'dfw_edd_license_status' );
?>
<?php if( false !== $license ) { ?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="<?php echo esc_attr( $value['id'] ); ?>"><?php echo esc_html( $value['title'] ); ?></label>
<?php echo $description['tooltip_html'];?>
</th>
<td class="forminp forminp-<?php echo sanitize_title( $value['type'] ) ?>">
<?php if( $status !== false && 'valid' == $status ) { ?>
<span style="color:green;"><?php _e( 'active' , 'deposits-for-woocommerce'); ?></span>
<?php wp_nonce_field( 'edd_sample_nonce', 'edd_sample_nonce' ); ?>
<input
name ="dfw_edd_deactivate_license"
id ="dfw_edd_deactivate_license"
type ="submit"
style="<?php echo esc_attr( $value['css'] ); ?>"
value="Deactivate"
class="<?php echo esc_attr( $value['class'] ); ?>"
/> <?php echo $description['description']; ?>
<?php } else { ?>
<?php wp_nonce_field( 'edd_sample_nonce', 'edd_sample_nonce' ); ?>
<input
name ="<?php echo esc_attr( $value['id'] ); ?>"
id ="<?php echo esc_attr( $value['id'] ); ?>"
type ="submit"
style="<?php echo esc_attr( $value['css'] ); ?>"
value="<?php echo esc_attr( $value['button_text'] ); ?>"
class="<?php echo esc_attr( $value['class'] ); ?>"
/> <?php echo $description['description']; ?>
<?php } ?>
</td>
</tr><?php
}
}
public function dfw_add_settings_tab( $settings_tabs ){
$settings_tabs[ 'dfw-deposits'] = __( 'Deposits', 'deposits-for-woocommerce' );
return $settings_tabs;
}
public function dfw_get_settings( $settings, $current_section ) {
$plans = DFW_Manage_Plans::get_plan_ids();
$license = get_option( 'dfw_edd_license_key' );
$deposit_options = array();
$amount = '';
if( 'dfw-deposits' == $current_section ){
if( 'percentage' == get_option( 'default_deposit_type' ) ) {
$amount = get_option('default_deposit_amount').'%';
}else if( 'fixed' == get_option( 'default_deposit_type' ) ) {
$amount = wc_price( get_option( 'default_deposit_amount' ) );
}
$deposit_options =
array(
array(
'name' => __( 'Deposits Configuration', 'deposits-for-woocommerce' ),
'type' => 'title',
'desc' => __( 'These settings affect all products sitewide. You can override these settings on a per product basis to make exceptions.', 'deposits-for-woocommerce' ),
'id' => 'default'
),
array(
'name' => __( 'Enable Deposits', 'deposits-for-woocommerce' ),
'type' => 'select',
'desc' => __( 'Choose whether deposits are enabled by default' ),
'desc_tip' => true,
'id' => 'default_deposits_enabled',
'options' => array(
'optional' => __( 'Deposits are optional', 'deposits-for-woocommerce' ),
'force' => __( 'Force Deposits', 'deposits-for-woocommerce' ),
'no' => __( 'No', 'deposits-for-woocommerce' )
)
),
array(
'name' => __( 'Default Deposit Type', 'deposits-for-woocommerce' ),
'type' => 'select',
'desc' => __( 'Select the default deposit type' ),
'desc_tip' => true,
'id' => 'default_deposit_type',
'options' => array(
'percentage' => __( 'Percentage', 'deposits-for-woocommerce' ),
'fixed' => __( 'Fixed Amount', 'deposits-for-woocommerce' ),
'payment_plan' => __( 'Payment Plan', 'deposits-for-woocommerce' )
)
),
array(
'name' => __( 'Default Deposit Amount', 'deposits-for-woocommerce'),
'type' => 'text',
'desc' => __( 'Default deposit amount','deposits-for-woocommerce'),
'desc_tip' => true,
'id' => 'default_deposit_amount',
),
array(
'name' => __( 'Default Payment Plans', 'deposits-for-woocommerce' ),
'type' => 'multiselect',
'class' => 'wc-enhanced-select',
'desc' => __( 'Select the payment plans to display' ),
'desc_tip' => true,
'default' => array(),
'id' => 'default_payment_plans',
'options' => $plans,
),
array(
'name' => __( 'Default payment type', 'deposits-for-woocommerce' ),
'type' => 'checkbox',
'desc' => __( 'Check if you want Pay Deposit to be default selection', 'deposits-for-woocommerce' ),
'id' => 'default_selection',
),
array(
'name' => __( 'Text to display on product page', 'deposits-for-woocommerce' ),
'type' => 'text',
'desc' => __( 'Text to display on the product page', 'deposits-for-woocommerce' ),
'desc_tip' => true,
'default' => 'Pay a deposit of '.$amount. ' per item',
'placeholder' => sanitize_text_field('Pay a deposit of '.$amount.' per item'),
'id' => 'deposit_text',
),
array( 'type' => 'sectionend', 'id' => 'default' ),
array(
'name' => __( 'Plugin License Options', 'deposits-for-woocommerce' ),
'type' => 'title',
'desc' => __( 'Enter the license key to activate', 'deposits-for-woocommerce' ),
'id' => 'dfw_license'
),
array(
'name' => __( 'License Key', 'deposits-for-woocommerce'),
'type' => 'text',
'desc' => __( 'Enter your License Key','deposits-for-woocommerce'),
'desc_tip' => true,
'id' => 'dfw_edd_license_key',
),
array(
'name' => __( 'Activate License', 'deposits-for-woocommerce'),
'type' => 'button',
'desc' => __( 'Activate your license','deposits-for-woocommerce'),
'button_text' => 'Activate',
'desc_tip' => true,
'class' => 'button-secondary',
'id' => 'dfw_edd_activate_license',
),
array( 'type' => 'sectionend', 'id' => 'dfw_license' ),
);
return $deposit_options;
} else {
return $settings;
}
}
}
$dfw_deposits_settings = new DFW_Deposits_Settings();