-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Наимнование файлов/функций/переменных. Файл readme.txt
- Loading branch information
Showing
10 changed files
with
477 additions
and
392 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/* | ||
Plugin Name: Cargo Delivery Service CDEK | ||
Plugin URI: http://mint-studio.org | ||
Description: Плагин рассчитывает стоимость доставки товара службой "Сдэк" | ||
Version: 1.0 | ||
Author: Mint Studio | ||
Author URI: http://mint-studio.org | ||
*/ | ||
|
||
/** | ||
* Register the scripts for the public-facing side of the site. | ||
* | ||
* @since 1.0.0 | ||
* | ||
*/ | ||
|
||
if ( ! defined( 'MY_PlUGIN_URL' ) ) | ||
define( 'MY_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); | ||
if ( ! defined( 'MY_PLUGIN_PATH' ) ) | ||
define( 'MY_PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); | ||
|
||
// Include script for the front end | ||
function cds_cdek_include_frontend_js() | ||
{ | ||
if ( is_cart() || is_checkout() ) { | ||
wp_enqueue_script('jquery-ui-1.12.1', MY_PLUGIN_URL . 'assets/js/jquery-ui-1.12.1.min.js', array( 'jquery' ), '1.12.1'); | ||
wp_enqueue_script('cds_cdek_script', MY_PLUGIN_URL . 'assets/js/CDS_CDEK_script.js', array('jquery' ), '1.0'); | ||
} | ||
} | ||
add_action( 'wp_enqueue_scripts', 'cds_cdek_include_frontend_js', 10); | ||
|
||
// Include script for the admin | ||
function cds_cdek_include_admin_js() { | ||
wp_enqueue_script( 'cds_cdek_admin_script', MY_PLUGIN_URL . 'assets/js/CDS_CDEK_script.js', array('jquery', 'jquery-ui-core'), '1.0', true ); | ||
} | ||
add_action('admin_enqueue_scripts', 'cds_cdek_include_admin_js', 5); | ||
|
||
// Include main function file | ||
include_once(MY_PLUGIN_PATH . 'inc/CDS_CDEK_function.php'); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
jQuery(document).ready(function($){ | ||
$('#billing_city_field').attr('style','position: relative;margin: 0; padding: 0;height: 0;background: none;opacity: 0;z-index: -1;') | ||
|
||
var apiUrl = "http://api.cdek.ru/city/getListByTerm/jsonp.php?callback=?"; | ||
|
||
if (window.location.protocol == 'https:'){ | ||
apiUrl = "https://api.cdek.ru/city/getListByTerm/jsonp.php?callback=?"; | ||
} | ||
|
||
// Получаем код города ( От клиента ) на странице оформления заказа | ||
$("#city_cdek").autocomplete({ | ||
source: function(request,response) { | ||
$.ajax({ | ||
url: apiUrl, | ||
dataType: "jsonp", | ||
data: { | ||
q: function () { return $("#city_cdek").val() }, | ||
name_startsWith: function () { return $("#city_cdek").val() } | ||
}, | ||
success: function(data) { | ||
response($.map(data.geonames, function(item) { | ||
return { | ||
label: item.name, | ||
value: item.name, | ||
id: item.id | ||
} | ||
})); | ||
} | ||
}); | ||
}, | ||
minLength: 1, | ||
select: function(event,ui) { | ||
$('#billing_city').val(ui.item.id); | ||
$(document.body).trigger("update_checkout"); | ||
} | ||
}); | ||
|
||
// Получаем код города ( От администратора ) в карточке товара | ||
$("#cdek_shipping_option_city_of_dispatch").autocomplete({ | ||
source: function(request,response) { | ||
$.ajax({ | ||
url: apiUrl, | ||
dataType: "jsonp", | ||
data: { | ||
q: function () { return $("#cdek_shipping_option_city_of_dispatch").val() }, | ||
name_startsWith: function () { return $("#cdek_shipping_option_city_of_dispatch").val() } | ||
}, | ||
success: function(data) { | ||
response($.map(data.geonames, function(item) { | ||
return { | ||
label: item.name, | ||
value: item.name, | ||
id: item.id | ||
} | ||
})); | ||
} | ||
}); | ||
}, | ||
minLength: 1, | ||
select: function(event,ui) { | ||
$('#cdek_shipping_option_city_code').val(ui.item.id); | ||
} | ||
}); | ||
|
||
// Получаем код города ( От администратора ) на странице настройки плагина | ||
$("#woocommerce_cdek-method_from_city").autocomplete({ | ||
source: function(request,response) { | ||
$.ajax({ | ||
url: apiUrl, | ||
dataType: "jsonp", | ||
data: { | ||
q: function () { return $("#woocommerce_cdek-method_from_city").val() }, | ||
name_startsWith: function () { return $("#woocommerce_cdek-method_from_city").val() } | ||
}, | ||
success: function(data) { | ||
response($.map(data.geonames, function(item) { | ||
return { | ||
label: item.name, | ||
value: item.name, | ||
id: item.id | ||
} | ||
})); | ||
} | ||
}); | ||
}, | ||
minLength: 1, | ||
select: function(event,ui) { | ||
$('#woocommerce_cdek-method_from_city_code').val(ui.item.id); | ||
} | ||
}); | ||
|
||
}); | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
add_action( 'woocommerce_product_options_shipping', 'cds_cdek_add_custom_shipping_fields' ); | ||
add_action( 'woocommerce_process_product_meta', 'cds_cdek_add_custom_shipping_fields_save' ); | ||
|
||
function cds_cdek_add_custom_shipping_fields() { | ||
global $woocommerce, $post; | ||
|
||
echo '<div class="options_group">'; | ||
|
||
woocommerce_wp_text_input( | ||
array( | ||
'id' => 'cds_cdek_shipping_option_city_of_dispatch', | ||
'label' => 'Город отправки', | ||
'placeholder' => 'Город отправки товара', | ||
'desc_tip' => 'true', | ||
'description' => 'Город откуда будет отправлен товар. По умолчанию - Краснодар. Используется для расчета стоимости доставки службой "СДЭК"' | ||
) | ||
); | ||
|
||
woocommerce_wp_hidden_input( | ||
array( | ||
'id' => 'cds_cdek_shipping_option_city_code', | ||
'value' => '' | ||
) | ||
); | ||
|
||
echo '</div>'; | ||
} | ||
|
||
function cds_cdek_add_custom_shipping_fields_save( $post_id ){ | ||
|
||
$cds_cdek_shipping_option_city_of_dispatch = $_POST['cds_cdek_shipping_option_city_of_dispatch']; | ||
update_post_meta( $post_id, 'cds_cdek_shipping_option_city_of_dispatch', sanitize_text_field( $cds_cdek_shipping_option_city_of_dispatch ) ); | ||
|
||
$cds_cdek_shipping_option_city_code = $_POST['cds_cdek_shipping_option_city_code']; | ||
update_post_meta( $post_id, 'cds_cdek_shipping_option_city_code', sanitize_text_field( $cds_cdek_shipping_option_city_code ) ); | ||
|
||
} | ||
|
||
?> |
Oops, something went wrong.