fully.', 'wcdt').'';
wp_send_json_success($output);
} else {
$rand_key = md5(wp_generate_password(12, true, true));
update_option(self::$option_name, $rand_key);
$how = array(
'starter' => base64_encode($starter),
'action' => 0,
'timer' => time(),
);
if (!is_object($result->message)) {
$how['message'] = $result->message;
} else {
foreach ($result->message as $message) {
foreach ($message as $msg) {
$how['message'] = $msg;
}
}
}
update_option($rand_key, json_encode($how));
$output = '
'.$how['message'].'
';
wp_send_json_success($output);
}
}
/**
* Set a schedule event for daily checking
*/
public function schedule_programs() {
if (! wp_next_scheduled ( 'wcdt_activation_daily_validator' )) {
wp_schedule_event(time(), 'daily', 'wcdt_activation_daily_validator');
}
}
/**
* Check license status every day
*/
public function daily_event() {
$private_session = get_option('wcdt_activation');
$now = json_decode(get_option($private_session));
if( isset($now) && !empty($now) ) {
$starter = (isset($now->starter) && !empty($now->starter)) ? base64_decode($now->starter) : '';
$result = self::is_valid($starter);
if( $result != null ) {
if ($result->status=='successful') {
delete_option($private_session);
$rand_key = md5(wp_generate_password(12, true, true));
update_option('wcdt_activation', $rand_key);
$how = array(
'starter' => base64_encode($starter),
'action' => 1,
'message' => $result->message,
'timer' => time(),
);
update_option($rand_key, json_encode($how));
} else {
delete_option($private_session);
$rand_key = md5(wp_generate_password(12, true, true));
update_option('wcdt_activation', $rand_key);
$how = array(
'starter' => base64_encode($starter),
'action' => 0,
'timer' => time(),
);
if (!is_object($result->message)) {
$how['message'] = $result->message;
} else {
foreach ($result->message as $message) {
foreach ($message as $msg) {
$how['message'] = $msg;
}
}
}
update_option($rand_key, json_encode($how));
}
}
}
}
/**
* Check license status
* If you want add an interrupt in your plugin or theme simply can use this static method: Zhaket_Guard_SDK::is_activated
* This will return true or false for license status
* @return bool
*/
public static function is_activated() {
return true;
$private_session = get_option('wcdt_activation');
$now = json_decode(get_option($private_session));
if( empty($now) ) {
return false;
} elseif($now->action != 1) {
return false;
} else {
return true;
}
}
/**
* @param $method
* @param array $params
*
* @return array|mixed|object
*/
public static function send_request( $method, $params=array() ) {
$param_string = http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,
self::$api_url.$method.'?'.$param_string
);
$content = curl_exec($ch);
return json_decode($content);
}
/**
* @param $license_token
*
* @return array|mixed|object
*/
public static function is_valid($license_token) {
$result = self::send_request('validation-license',array('token'=>$license_token,'domain'=>self::get_host()));
return $result;
}
/**
* @param $license_token
* @param $product_token
*
* @return array|mixed|object
*/
public static function install($license_token, $product_token) {
$result = self::send_request('install-license',array('product_token'=>$product_token,'token'=>$license_token,'domain'=>self::get_host()));
return $result;
}
/**
* @return string
*/
public static function get_host() {
$possibleHostSources = array('HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR');
$sourceTransformations = array(
"HTTP_X_FORWARDED_HOST" => function($value) {
$elements = explode(',', $value);
return trim(end($elements));
}
);
$host = '';
foreach ($possibleHostSources as $source)
{
if (!empty($host)) break;
if (empty($_SERVER[$source])) continue;
$host = $_SERVER[$source];
if (array_key_exists($source, $sourceTransformations))
{
$host = $sourceTransformations[$source]($host);
}
}
// Remove port number from host
$host = preg_replace('/:\d+$/', '', $host);
// remove www from host
$host = str_ireplace('www.', '', $host);
return trim($host);
}
public function backend_enqueue_scripts() {
if(!self::is_activated()) return;
$screen = get_current_screen();
if(strpos($screen->base, 'wc_delivery_time_settings') !== false) {
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_style('backend-styles', WCDT_URL . 'assets/css/backend.css', '', WCDT_VERSION);
wp_enqueue_style('dt-select2', WCDT_URL . 'assets/css/libraries/select2.min.css','', WCDT_VERSION);
wp_enqueue_style('jquery-ui', WCDT_URL . 'assets/css/libraries/jquery-ui.css', '', WCDT_VERSION);
wp_enqueue_script('dt-datepicker', WCDT_URL . 'assets/js/libraries/datepicker.min.js', array('jquery'), WCDT_VERSION, true);
wp_enqueue_script('dt-datepicker-fa', WCDT_URL . 'assets/js/libraries/datepicker.fa.min.js', array('jquery'), WCDT_VERSION, true);
wp_enqueue_script('dt-select2', WCDT_URL . 'assets/js/libraries/select2.full.min.js', array('jquery'), WCDT_VERSION, true);
wp_enqueue_script('dt-select2-fa', WCDT_URL . 'assets/js/libraries/select2.i18n/fa.js', array('jquery'), WCDT_VERSION, true);
wp_enqueue_script('backend-listcities', WCDT_URL . 'assets/js/libraries/listcities.js', ['jquery'], WCDT_VERSION);
wp_enqueue_script('backend-scripts', WCDT_URL . 'assets/js/backend.js', ['wp-color-picker'], WCDT_VERSION, true);
wp_localize_script(
'backend-scripts',
'dt_ajax',
array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce'),
)
);
if ( class_exists( 'PWS_VERSION' ) ) {
$_province = get_terms(array(
'taxonomy' => 'state_city',
'hide_empty' => false,
'parent' => 0
));
$province = wp_list_pluck($_province, 'name', 'term_id');
$cities = array();
foreach ($province as $key => $value) {
$_cities = get_terms(array(
'taxonomy' => 'state_city',
'hide_empty' => false,
'parent' => $key
));
$cities[$key] = wp_list_pluck($_cities, 'name', 'term_id');
}
wp_localize_script(
'backend-listcities',
'dt_pws_listcities',
array(
'url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('ajax-nonce'),
'province' => $province,
'cities' => $cities
)
);
}
}
if($screen->id == 'shop_order') {
wp_enqueue_style('backend-order-css', WCDT_URL . 'assets/css/order.css', '', WCDT_VERSION);
wp_enqueue_style('wcdt-backend-persian-datepicker-css', WCDT_URL . 'assets/libraries/persianDatepicker/persian-datepicker.min.css', '', WCDT_VERSION);
wp_dequeue_style('pw-datepicker-css');
wp_dequeue_script('pw-datepicker-js');
wp_enqueue_script('wcdt-backend-persian-date-js', WCDT_URL . 'assets/libraries/persianDatepicker/persian-date.min.js', ['jquery'], WCDT_VERSION, true);
wp_enqueue_script('wcdt-backend-persian-datepicker-js', WCDT_URL . 'assets/libraries/persianDatepicker/persian-datepicker.min.js', ['jquery', 'wcdt-backend-persian-date-js'], WCDT_VERSION, true);
wp_enqueue_script('backend-order-js', WCDT_URL . 'assets/js/order.js', ['jquery', 'wcdt-backend-persian-date-js', 'wcdt-backend-persian-datepicker-js'], WCDT_VERSION, true);
$params_order = [];
if ( class_exists( 'Persian_Woocommerce_Core' ) ) {
$pw_jalali = get_option('PW_Options');
if(isset($pw_jalali) and !empty($pw_jalali)) {
$pw_jalali = $pw_jalali['enable_jalali_datepicker'];
$params_order['pw_jalali'] = $pw_jalali;
}
}
$calendar_type = wcdt_get_option('calendar');
if( !isset($calendar_type) or empty($calendar_type) ) $calendar_type = 'jalali';
$params_order['calendar'] = $calendar_type;
$params_order['language'] = [
'select_time_error' => __('Select the desired time', 'wcdt'),
'date' => __('Date', 'wcdt'),
'time' => __('Time', 'wcdt'),
];
wp_localize_script(
'backend-order-js',
'wcdt_order_params',
$params_order
);
}
}
public function frontend_enqueue_scripts() {
if(is_checkout()) {
wp_enqueue_style('dt-frontend-styles', WCDT_URL . 'assets/css/frontend.css');
wp_enqueue_script('dt-frontend-scripts', WCDT_URL . 'assets/js/frontend.js', array('jquery'), '2', true);
}
}
public function add_product_custom_field_simple(){
echo '';
woocommerce_wp_text_input( array(
'id' => '_delivery_ready_in_days',
'label' => __('When Product is ready to send', 'wcdt'),
'placeholder' => __('for example: 3', 'wcdt'),
'desc_tip' => true,
'description' => __('If your product need X days to be ready to send to customer, you can use this option. If you fill this option, in delivery table, the table will be skip for start in X days.', 'wcdt'),
'type' => 'number'
));
echo '
';
}
public function save_product_custom_field_simple($post_id){
$product_delivery_ready = isset( $_POST['_delivery_ready_in_days'] ) ? $_POST['_delivery_ready_in_days'] : '';
if(isset($product_delivery_ready) and !empty($product_delivery_ready)) {
update_post_meta($post_id, '_delivery_ready_in_days', esc_attr( $product_delivery_ready ));
} else {
delete_post_meta($post_id, '_delivery_ready_in_days');
}
}
public function add_product_custom_field_variation( $loop, $variation_data, $variation ) {
echo '';
woocommerce_wp_text_input(
array(
'id' => '_delivery_ready_in_days[' . $variation->ID . ']',
'label' => __('When Product is ready to send', 'wcdt'),
'placeholder' => __('for example: 3', 'wcdt'),
'desc_tip' => true,
'description' => __('If your product need X days to be ready to send to customer, you can use this option. If you fill this option, in delivery table, the table will be skip for start in X days.', 'wcdt'),
'value' => get_post_meta( $variation->ID, '_delivery_ready_in_days', true )
)
);
echo '
';
}
function save_product_custom_field_variation( $post_id ){
$product_delivery_ready = isset( $_POST['_delivery_ready_in_days'][ $post_id ] ) ? $_POST['_delivery_ready_in_days'][ $post_id ] : '';
if(isset($product_delivery_ready) and !empty($product_delivery_ready)) {
update_post_meta($post_id, '_delivery_ready_in_days', esc_attr( $product_delivery_ready ));
} else {
delete_post_meta($post_id, '_delivery_ready_in_days');
}
}
public function delivery_time_shortcode_callback( $atts ) {
$atts = shortcode_atts( array(
'order_id' => ''
), $atts, 'delivery_time' );
$delivery_info = WC_Delivery_Time_Show::get_delivery_meta_item( $atts['order_id'] );
if(isset($delivery_info) && !empty($delivery_info)){
$delivery_date = $delivery_info[0]['delivery_date'];
$delivery_hour = $delivery_info[0]['delivery_time'];
$result = ''. __('delivery date and time: ', 'wcdt') .'' . __('date: ', 'wcdt') . wcdt_convert_number(WC_Delivery_Time_Show::get_date_i18n($delivery_date)) . ' - ' . __('time: ', 'wcdt') .$delivery_hour.'
';
}
return $result;
}
public function disable_wcdt_field_shipping_methods() {
$fastsending_status = wcdt_get_option('fastsending_status');
if(empty($fastsending_status) or $fastsending_status !== 'enable') return;
$shipping_methods = WC()->shipping->get_shipping_methods();
unset($shipping_methods['fastsending']);
foreach($shipping_methods as $key => $value) {
add_filter('woocommerce_shipping_instance_form_fields_'.$key, function ($fields) {
$fields['disable_wcdt'] = [
'title' => 'غیرفعال کردن زمان ارسال',
'type' => 'select',
'class' => 'wc-enhanced-select',
'default' => 'no',
'description' => 'این کنترل مشخص میکند که بعد از انتخاب روش ارسال، زمان ارسال نمایش داده شود یا نه!',
'options' => [
'no' => __('no', 'wcdt'),
'yes' => __('yes', 'wcdt'),
],
'desc_tip' => true
];
return $fields;
}, 10, 1);
}
}
}