| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
exit; // Exit if accessed directly |
| 4 |
} |
| 5 |
class WPC_MP_Settings { |
| 6 |
public function __construct(){ |
| 7 |
add_action( 'admin_menu', array($this, 'mp_add_admin_menu') ); |
| 8 |
add_action( 'admin_init', array($this, 'wpc_mp_settings_init') ); |
| 9 |
add_action('wpc_add_settings_nav', array( $this, 'wpc_mp_add_settings_nav') ); |
| 10 |
} |
| 11 |
public function mp_add_admin_menu() { |
| 12 |
add_submenu_page( |
| 13 |
'wpcargo-settings', |
| 14 |
esc_html__( 'Multiple Package Settings', 'wpcargo' ), |
| 15 |
esc_html__( 'Multiple Package Settings', 'wpcargo' ), |
| 16 |
'manage_options', |
| 17 |
'admin.php?page=wpc-multiple-package' |
| 18 |
); |
| 19 |
add_submenu_page( 'wpc-multiple-package', |
| 20 |
esc_html__( 'Multiple Package Settings', 'wpcargo' ), |
| 21 |
esc_html__( 'Multiple Package Settings', 'wpcargo' ), |
| 22 |
'manage_options', |
| 23 |
'wpc-multiple-package', |
| 24 |
array($this, 'mp_options_page') |
| 25 |
); |
| 26 |
} |
| 27 |
public function wpc_mp_settings_init( ) { |
| 28 |
register_setting( 'wpc_mp_pluginPage', 'wpc_mp_settings' ); |
| 29 |
add_settings_section( |
| 30 |
'wpc_mp_pluginPage_section', |
| 31 |
'', |
| 32 |
array($this, 'wpc_mp_settings_section_callback'), |
| 33 |
'wpc_mp_pluginPage' |
| 34 |
); |
| 35 |
add_settings_field( |
| 36 |
'wpc_mp_enable_admin', |
| 37 |
esc_html__( 'Enable Multiple Package on Admin?', 'wpcargo' ), |
| 38 |
array( $this, 'wpc_mp_enable_admin_render' ), |
| 39 |
'wpc_mp_pluginPage', |
| 40 |
'wpc_mp_pluginPage_section' |
| 41 |
); |
| 42 |
add_settings_field( |
| 43 |
'wpc_mp_enable_frontend', |
| 44 |
esc_html__( 'Enable Multiple Package on Results?', 'wpcargo' ), |
| 45 |
array( $this, 'wpc_mp_enable_frontend_render' ), |
| 46 |
'wpc_mp_pluginPage', |
| 47 |
'wpc_mp_pluginPage_section' |
| 48 |
); |
| 49 |
add_settings_field( |
| 50 |
'wpc_mp_enable_dimension_unit', |
| 51 |
esc_html__( 'Enable Dimension Unit?', 'wpcargo' ), |
| 52 |
array( $this, 'wpc_mp_enable_dimension_unit_render' ), |
| 53 |
'wpc_mp_pluginPage', |
| 54 |
'wpc_mp_pluginPage_section' |
| 55 |
); |
| 56 |
add_settings_field( |
| 57 |
'wpc_mp_enable_dimension_unit', |
| 58 |
esc_html__( 'Enable Dimension Unit?', 'wpcargo' ), |
| 59 |
array( $this, 'wpc_mp_enable_dimension_unit_render' ), |
| 60 |
'wpc_mp_pluginPage', |
| 61 |
'wpc_mp_pluginPage_section' |
| 62 |
); |
| 63 |
add_settings_field( |
| 64 |
'wpcargo_dim_divisor', |
| 65 |
esc_html__( 'Dimension Divisor', 'wpcargo' ), |
| 66 |
array( $this, 'wpcargo_dim_divisor_render' ), |
| 67 |
'wpc_mp_pluginPage', |
| 68 |
'wpc_mp_pluginPage_section' |
| 69 |
); |
| 70 |
add_settings_field( |
| 71 |
'wpc_mp_dimension_unit', |
| 72 |
esc_html__( 'Dimension Unit', 'wpcargo' ), |
| 73 |
array( $this, 'wpc_mp_dimension_unit_render' ), |
| 74 |
'wpc_mp_pluginPage', |
| 75 |
'wpc_mp_pluginPage_section' |
| 76 |
); |
| 77 |
add_settings_field( |
| 78 |
'wpc_mp_weight_unit', |
| 79 |
esc_html__( 'Weight Unit', 'wpcargo' ), |
| 80 |
array( $this, 'wpc_mp_weight_unit_render' ), |
| 81 |
'wpc_mp_pluginPage', |
| 82 |
'wpc_mp_pluginPage_section' |
| 83 |
); |
| 84 |
add_settings_field( |
| 85 |
'wpc_mp_piece_type', |
| 86 |
esc_html__( 'Piece Type Selection', 'wpcargo' ), |
| 87 |
array( $this, 'wpc_mp_piece_type_render' ), |
| 88 |
'wpc_mp_pluginPage', |
| 89 |
'wpc_mp_pluginPage_section' |
| 90 |
); |
| 91 |
} |
| 92 |
public function wpc_mp_enable_admin_render( ) { |
| 93 |
$options = get_option( 'wpc_mp_settings' ); |
| 94 |
?> |
| 95 |
<input type='checkbox' name='wpc_mp_settings[wpc_mp_enable_admin]' <?php isset($options['wpc_mp_enable_admin']) ? checked( $options['wpc_mp_enable_admin'] , 1 ) : ''; ?> value='1'> |
| 96 |
<p><i><?php esc_html_e('If checked you will enable the multiple package on your shipment admin dashboard.', 'wpcargo' ); ?></i></p> |
| 97 |
<?php |
| 98 |
} |
| 99 |
public function wpc_mp_enable_frontend_render( ) { |
| 100 |
$options = get_option( 'wpc_mp_settings' ); |
| 101 |
?> |
| 102 |
<input type='checkbox' name='wpc_mp_settings[wpc_mp_enable_frontend]' <?php isset($options['wpc_mp_enable_frontend']) ? checked( $options['wpc_mp_enable_frontend'], 1 ) : ''; ?> value='1'> |
| 103 |
<p><i><?php esc_html_e('If checked you will enable the multiple package on your shipment results.', 'wpcargo'); ?></i></p> |
| 104 |
<?php |
| 105 |
} |
| 106 |
public function wpc_mp_enable_dimension_unit_render( ) { |
| 107 |
$options = get_option( 'wpc_mp_settings' ); |
| 108 |
?> |
| 109 |
<input type='checkbox' name='wpc_mp_settings[wpc_mp_enable_dimension_unit]' <?php isset($options['wpc_mp_enable_dimension_unit']) ? checked( $options['wpc_mp_enable_dimension_unit'], 1 ) : ''; ?> value='1'> |
| 110 |
<p><i><?php esc_html_e('If checked you will enable the dimension unit.', 'wpcargo'); ?></i></p> |
| 111 |
<?php |
| 112 |
} |
| 113 |
public function wpcargo_dim_divisor_render(){ |
| 114 |
$options = get_option( 'wpc_mp_settings' ); |
| 115 |
$options = $options ? $options : array(); |
| 116 |
?> |
| 117 |
<input type='number' name='wpc_mp_settings[wpcargo_dim_divisor]' value="<?php echo array_key_exists( 'wpcargo_dim_divisor', $options ) ? esc_html( $options['wpcargo_dim_divisor']) : '' ; ?>"> |
| 118 |
<p class="description"><?php esc_html_e( 'Note: These values are used in calculating Volumetric Weight.', 'wpcargo' ); ?></p> |
| 119 |
<p class="description"><strong><?php esc_html_e( 'Formula', 'wpcargo' ); ?>: <?php esc_html_e( 'Volumetric Weight.', 'wpcargo' ); ?> = [( <?php esc_html_e( 'Length', 'wpcargo' ); ?> X <?php esc_html_e( 'Width', 'wpcargo' ); ?> X <?php esc_html_e( 'Height', 'wpcargo' ); ?> ) / <?php esc_html_e('Dimension Divisor', 'wpcargo'); ?>] X <?php esc_html_e('Quantity', 'wpcargo'); ?></strong></p> |
| 120 |
<?php |
| 121 |
} |
| 122 |
public function wpc_mp_dimension_unit_render() { |
| 123 |
$options = get_option( 'wpc_mp_settings' ); |
| 124 |
$options = $options ? $options : array(); |
| 125 |
$unit = array_key_exists( 'wpc_mp_dimension_unit', $options ) ? $options['wpc_mp_dimension_unit'] : 'cm' ; |
| 126 |
?> |
| 127 |
<select name="wpc_mp_settings[wpc_mp_dimension_unit]" id="wpc_mp_dimension_unit" required> |
| 128 |
<?php foreach( wpcargo_package_dim_units() as $dim_unit): ?> |
| 129 |
<option value="<?php echo esc_html($dim_unit); ?>" <?php selected( $unit, $dim_unit, true ); ?>><?php echo esc_html($dim_unit); ?></option> |
| 130 |
<?php endforeach; ?> |
| 131 |
</select> |
| 132 |
<p><i><?php esc_html_e('This will be display in the package Dimension. The default is cm.', 'wpcargo'); ?></i></p> |
| 133 |
<?php |
| 134 |
} |
| 135 |
public function wpc_mp_weight_unit_render() { |
| 136 |
$options = get_option( 'wpc_mp_settings' ); |
| 137 |
$unit = array_key_exists( 'wpc_mp_weight_unit', $options ) ? $options['wpc_mp_weight_unit'] : 'lbs' ; |
| 138 |
?> |
| 139 |
<select name="wpc_mp_settings[wpc_mp_weight_unit]" id="wpc_mp_weight_unit" required> |
| 140 |
<?php foreach( wpcargo_package_weight_units() as $dim_unit): ?> |
| 141 |
<option value="<?php echo esc_html($dim_unit); ?>" <?php selected( $unit, $dim_unit, true ); ?>><?php echo esc_html($dim_unit); ?></option> |
| 142 |
<?php endforeach; ?> |
| 143 |
</select> |
| 144 |
<p><i><?php esc_html_e('This will be display in the package Weight. The default is lbs.', 'wpcargo'); ?></i></p> |
| 145 |
<?php |
| 146 |
} |
| 147 |
public function wpc_mp_piece_type_render() { |
| 148 |
$options = get_option( 'wpc_mp_settings' ); |
| 149 |
?> |
| 150 |
<textarea cols='40' rows='5' name='wpc_mp_settings[wpc_mp_piece_type]'><?php echo esc_html($options['wpc_mp_piece_type']); ?></textarea> |
| 151 |
<p><i><?php esc_html_e('This will be the selection for the Piece Type for the Package Information section. Comma separated ( Ex. Pallet, Carton, Crate, Loose, Others)', 'wpcargo'); ?></i></p> |
| 152 |
<?php |
| 153 |
} |
| 154 |
public function wpc_mp_settings_section_callback( ) { |
| 155 |
echo '<p class="description">'.esc_html__( 'Settings for Multiple Package, please fill out the fields below.', 'wpcargo' ).'</p>'; |
| 156 |
} |
| 157 |
public function mp_options_page( ) { |
| 158 |
?><h1><?php esc_html_e('Multiple Package', 'wpcargo'); ?></h1><?php |
| 159 |
require_once( WPCARGO_PLUGIN_PATH.'admin/templates/admin-navigation.tpl.php' ); |
| 160 |
?> |
| 161 |
<div class="postbox"> |
| 162 |
<div class="inside"> |
| 163 |
<form action='options.php' method='post'> |
| 164 |
<?php |
| 165 |
settings_fields( 'wpc_mp_pluginPage' ); |
| 166 |
do_settings_sections( 'wpc_mp_pluginPage' ); |
| 167 |
submit_button(); |
| 168 |
?> |
| 169 |
</form> |
| 170 |
</div> |
| 171 |
</div> |
| 172 |
<?php |
| 173 |
} |
| 174 |
public function wpc_mp_add_settings_nav() { |
| 175 |
$view = sanitize_text_field( $_GET['page'] ); |
| 176 |
?> |
| 177 |
<a class="nav-tab <?php echo ( $view == 'wpc-multiple-package') ? 'nav-tab-active' : '' ; ?>" href="<?php echo esc_url(admin_url().'admin.php?page=wpc-multiple-package'); ?>" ><?php esc_html_e('Multiple Package Settings', 'wpcargo'); ?></a> |
| 178 |
<?php |
| 179 |
} |
| 180 |
} |
| 181 |
$wpc_wpc_mp_settings = new WPC_MP_Settings; |