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
<?php
class prdd_estimate_delivery {
public function __construct() {
add_action( 'prdd_before_method_select', array( &$this, 'prdd_before_method_select' ), 10, 1 );
add_filter( 'prdd_save_product_settings', array( &$this, 'prdd_save_product_settings' ), 10, 2 );
}
public function prdd_before_method_select( $product_id ) {
$prdd_settings = get_post_meta( $product_id, 'woocommerce_prdd_settings', true );
$prdd_delivery_options_delivery_calendar = 'checked';
$prdd_delivery_options_text_block = '';
if ( isset( $prdd_settings[ 'prdd_delivery_options' ] ) && $prdd_settings[ 'prdd_delivery_options' ] == 'text_block' ) {
$prdd_delivery_options_text_block = "checked";
$prdd_delivery_options_delivery_calendar = '';
} else if ( isset( $prdd_settings[ 'prdd_delivery_options' ] ) && $prdd_settings[ 'prdd_delivery_options' ] == 'delivery_calendar' ) {
$prdd_delivery_options_delivery_calendar = "checked";
$prdd_delivery_options_text_block = '';
}
$prdd_estimate_days = 3;
if( isset( $prdd_settings[ 'prdd_estimate_days' ] ) ) {
$prdd_estimate_days = $prdd_settings[ 'prdd_estimate_days' ];
}
$prdd_estimate_delivery_display_days = 'checked';
$prdd_estimate_delivery_display_specific_date = '';
if ( isset( $prdd_settings[ 'prdd_estimate_delivery_display' ] ) && $prdd_settings[ 'prdd_estimate_delivery_display' ] == 'days' ) {
$prdd_estimate_delivery_display_days = "checked";
$prdd_estimate_delivery_display_specific_date = '';
} else if ( isset( $prdd_settings[ 'prdd_estimate_delivery_display' ] ) && $prdd_settings[ 'prdd_estimate_delivery_display' ] == 'specific_date' ) {
$prdd_estimate_delivery_display_specific_date = "checked";
$prdd_estimate_delivery_display_days = '';
}
?>
<tr class="prdd_delivery_options">
<th>
<?php _e( 'Delivery Option:', 'woocommerce-prdd' ); ?>
</th>
<td style="width:380px">
<input type="radio" name="prdd_delivery_options" id="prdd_delivery_options" value="delivery_calendar"<?php echo $prdd_delivery_options_delivery_calendar; ?>/><?php _e( 'Calendar', 'order-delivery-date' ) ;?> </input>
<input type="radio" name="prdd_delivery_options" id="prdd_delivery_options" value="text_block"<?php echo $prdd_delivery_options_text_block; ?>/><?php _e( 'Text block', 'order-delivery-date' ) ;?> </input>
</td>
<td>
<img class="help_tip" width="16" height="16" data-tip="<?php _e( 'Choose the delivery date option to be displayed on the product page.', 'woocommerce-prdd' ); ?>" src="<?php echo plugins_url() ;?>/woocommerce/assets/images/help.png"/>
</td>
</tr>
<tr class="prdd_estimate_days">
<th>
<?php _e( 'Minimum Delivery Days required:', 'woocommerce-prdd' ); ?>
</th>
<td style="width:380px">
<input type="text" name="prdd_estimate_days" id="prdd_estimate_days" value="<?php echo $prdd_estimate_days; ?>" />
</td>
<td>
<img class="help_tip" width="16" height="16" data-tip="<?php _e( 'Number of days required to deliver an order after submitting it.', 'woocommerce-prdd' ); ?>" src="<?php echo plugins_url() ;?>/woocommerce/assets/images/help.png"/>
</td>
</tr>
<tr class="prdd_estimate_delivery_display">
<th>
<?php _e( 'Display Delivery details:', 'woocommerce-prdd' ); ?>
</th>
<td style="width:380px">
<input type="radio" name="prdd_estimate_delivery_display" id="prdd_estimate_delivery_display" value="days"<?php echo $prdd_estimate_delivery_display_days; ?>/><?php _e( 'Business Days', 'order-delivery-date' ) ;?> </input>
<input type="radio" name="prdd_estimate_delivery_display" id="prdd_estimate_delivery_display" value="specific_date"<?php echo $prdd_estimate_delivery_display_specific_date; ?>/><?php _e( 'Specific Date', 'order-delivery-date' ) ;?> </input>
</td>
<td>
<img class="help_tip" width="16" height="16" data-tip="<?php _e( 'Display estimated delivery details based on the number of business days or an estimated delivery date.', 'woocommerce-prdd' ); ?>" src="<?php echo plugins_url() ;?>/woocommerce/assets/images/help.png"/>
</td>
</tr>
<script type='text/javascript'>
jQuery( document ).ready( function(){
if ( jQuery( "input[type=radio][id=\"prdd_delivery_options\"][value=\"delivery_calendar\"]" ).is(":checked") ) {
jQuery( "#prdd_method" ).show();
jQuery( "#prdd_enable_weekday" ).show();
jQuery( "#selective_delivery" ).show();
jQuery( "#prdd_lockout_date" ).show();
jQuery( "#prdd_time" ).show();
jQuery( "#add_button" ).show();
jQuery( ".prdd_estimate_days" ).hide();
jQuery( ".prdd_estimate_delivery_display" ).hide();
} else if ( jQuery( "input[type=radio][id=\"prdd_delivery_options\"][value=\"text_block\"]" ).is( ":checked" ) ) {
jQuery( "#prdd_method" ).hide();
jQuery( "#prdd_enable_weekday" ).hide();
jQuery( "#selective_delivery" ).hide();
jQuery( "#prdd_lockout_date" ).hide();
jQuery( "#prdd_time" ).hide();
jQuery( "#add_button" ).hide();
jQuery( ".prdd_estimate_days" ).show();
jQuery( ".prdd_estimate_delivery_display" ).show();
}
jQuery( "input[type=radio][id=\"prdd_delivery_options\"]" ).on( 'change', function() {
if ( jQuery( this ).is(':checked') ) {
var value = jQuery( this ).val();
if( value == 'delivery_calendar' ) {
jQuery( "#prdd_method" ).show();
jQuery( "#prdd_enable_weekday" ).show();
jQuery( "#selective_delivery" ).show();
jQuery( "#prdd_lockout_date" ).show();
jQuery( "#prdd_time" ).show();
jQuery( "#add_button" ).show();
jQuery( ".prdd_estimate_days" ).hide();
jQuery( ".prdd_estimate_delivery_display" ).hide();
} else if( value == 'text_block' ) {
jQuery( "#prdd_method" ).hide();
jQuery( "#prdd_enable_weekday" ).hide();
jQuery( "#selective_delivery" ).hide();
jQuery( "#prdd_lockout_date" ).hide();
jQuery( "#prdd_time" ).hide();
jQuery( "#add_button" ).hide();
jQuery( ".prdd_estimate_days" ).show();
jQuery( ".prdd_estimate_delivery_display" ).show();
}
}
} );
});
</script>
<?php
}
public function prdd_save_product_settings( $prdd_settings, $product_id ) {
$prdd_delivery_options = '';
if ( isset( $_POST[ 'prdd_delivery_options' ] ) ) {
$prdd_delivery_options = $_POST[ 'prdd_delivery_options' ];
}
$prdd_estimate_days = 3;
if( isset( $_POST[ 'prdd_estimate_days' ] ) ) {
$prdd_estimate_days = $_POST[ 'prdd_estimate_days' ];
}
$prdd_estimate_delivery_display = '';
if( isset( $_POST[ 'prdd_estimate_delivery_display' ] ) ) {
$prdd_estimate_delivery_display = $_POST[ 'prdd_estimate_delivery_display' ];
}
$prdd_settings[ 'prdd_delivery_options' ] = $prdd_delivery_options;
$prdd_settings[ 'prdd_estimate_days' ] = $prdd_estimate_days;
$prdd_settings[ 'prdd_estimate_delivery_display' ] = $prdd_estimate_delivery_display;
return $prdd_settings;
}
}
$prdd_estimate_delivery = new prdd_estimate_delivery();