Commit bc677d21 by Pham Huy

update form checkout

parent 9ec1ec7d
......@@ -287,7 +287,10 @@ p.title-item-sidebar {
width: 58%;
}
.woocommerce #respond input#submit.alt, .woocommerce a.button.alt, .woocommerce button.button.alt, .woocommerce input.button.alt{
background-color: #ed6549;
background-color: #ed2027;
}
.woocommerce #respond input#submit.alt:hover, .woocommerce a.button.alt:hover, .woocommerce button.button.alt:hover, .woocommerce input.button.alt:hover{
background-color: #56bc86;
}
.woocommerce table.shop_attributes td{
padding: 0px 15px;
......
......@@ -68,7 +68,7 @@ $img_homepage = wp_get_attachment_image_src(70, '59x59');
<div class="container">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center">
<span>Copyright © 2019 by DCV. JSC</span>
<span>Copyright © 2019 by DCV., JSC</span>
</div>
</div>
</div>
......
......@@ -1002,7 +1002,7 @@ function mst_checkout_field($checkout) {
'class' => array(
'mst-field form-row-wide'
) ,
'label' => __('Mã số thuế') ,
'label' => __('Mã số thuế công ty') ,
'placeholder' => __('Nhập mã số thuế') ,
) ,
$checkout->get_value('mst_checkout_field'));
......@@ -1022,12 +1022,14 @@ function custom_checkout_field_update_order_meta($order_id) {
}
/**
* Remove postcode field
* Remove postcode field, country
*/
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
function custom_override_checkout_fields( $fields ) {
unset($fields['billing']['billing_postcode']);
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_last_name']);
return $fields;
}
......@@ -1048,4 +1050,117 @@ function custom_checkout_field_order_meta_keys( $keys ) {
// return false;
// }
// return $passed_validation;
// }
\ No newline at end of file
// }
function get_taxcode_ahoadon( $data ) {
if ( !validate_taxcode( $data['taxcode'] ) ) {
$data_res->status = 400;
$data_res->message = 'Mã số thuế không hợp lệ';
// return new WP_Error( 'validate_taxcode', 'Mã số thuế không hợp lệ', array( 'status' => 400 ) );
$response = new WP_REST_Response($data_res);
return $response;
}else{
$url = 'https://thongtindoanhnghiep.co/api/company/' . $data['taxcode'];
}
$tt = wp_remote_get( $url );
$data_res->data = json_decode($tt['body']);
$data_res->status = 200;
$response = new WP_REST_Response($data_res);
$response->set_status(200);
return $response;
}
function validate_taxcode($mst){
$result = true;
if (strlen($mst) == 10 || strlen($mst) == 14) {
if (strlen($mst) == 14) {
$result = (is_numeric(substr($mst, -3))) ? true : false;
$string = $mst[10];
if ($string == '_' || $string == '-') {
$result = true;
} else {
$result = false;
}
}
$kt = substr($mst, 0, 10);
$tong = 0;
$tong += (int)substr($kt, 0, 1) * 31;
$tong += (int)substr($kt, 1, 1) * 29;
$tong += (int)substr($kt, 2, 1) * 23;
$tong += (int)substr($kt, 3, 1) * 19;
$tong += (int)substr($kt, 4, 1) * 17;
$tong += (int)substr($kt, 5, 1) * 13;
$tong += (int)substr($kt, 6, 1) * 7;
$tong += (int)substr($kt, 7, 1) * 5;
$tong += (int)substr($kt, 8, 1) * 3;
$check = 10 - ($tong % 11);
if (substr($kt, 9, 1) != $check) {
$result = false;
}
} else {
$result = false;
}
return $result;
}
/**
* Rest api init taxcode
*/
add_action( 'rest_api_init', function () {
register_rest_route( 'ahoadon/v1', '/taxcode/(?P<taxcode>\d+)', array(
'methods' => 'GET',
'callback' => 'get_taxcode_ahoadon',
'args' => array(
'taxcode' => array(
'validate_callback' => 'is_numeric'
),
),
) );
} );
/**
* change order billing fields on checkout page
*/
add_filter("woocommerce_checkout_fields", "custom_order_fields");
function custom_order_fields($fields) {
$order = array(
"billing_first_name",
"billing_email",
"billing_phone",
"billing_company",
"billing_address_1",
"billing_city",
);
foreach($order as $field)
{
$ordered_fields[$field] = $fields["billing"][$field];
}
$fields["billing"] = $ordered_fields;
$fields['billing']['billing_company']['priority'] = 10;
$fields['billing']['billing_address_1']['priority'] = 20;
$fields['billing']['billing_city']['priority'] = 40;
$fields['billing']['billing_first_name']['priority'] = 50;
// $fields['billing']['billing_last_name']['priority'] = 60;
$fields['billing']['billing_phone']['priority'] = 60;
$fields['billing']['billing_email']['priority'] = 70;
return $fields;
}
/**
* customize_override_checkout_field
*/
add_filter( 'woocommerce_checkout_fields' , 'customize_override_checkout_field' );
function customize_override_checkout_field($field) {
$field['billing']['billing_address_1']['required'] = false;
$field['billing']['billing_city']['required'] = false;
$field['billing']['billing_email']['required'] = false;
$field['billing']['billing_first_name']['label'] = 'Người liên hệ';
$field['billing']['billing_first_name']['class'] = array('form-row-wide');
return $field;
}
......@@ -69,55 +69,72 @@ if ( ! $checkout->is_registration_enabled() && $checkout->is_registration_requir
var loading = $('.loading');
var noti = $('.notify-mst');
$( 'i#search-taxcode' ).on( 'click', function() {
$(this).append(loading);
$('#mst_checkout_field_field').append(noti);
var taxcode = $('input#mst_checkout_field').val();
$('input#mst_checkout_field').val(taxcode.trim());
$.ajax({
// url: "http://edupham.com/api/v1/get-company-info-by-taxcode",
url: "https://thongtindoanhnghiep.co/api/company/3901212654",
// data: {
// "taxcode": taxcode
// },
dataType: "json",
type: 'GET',
beforeSend: function () {
$('.loading').css('display','block');
},
success: function( response ) {
if( taxcode.length < 1 ){
noti.text('Mã số thuế không hợp lệ');
noti.css('display','block');
$('.loading').css('display','none');
// console.log(response);
if (response.code == 400) {
noti.text(response.message);
}else{
if (!$.isNumeric(taxcode)) {
noti.text('Mã số thuế không hợp lệ');
noti.css('display','block');
$( 'input#billing_company' ).val('');
$( 'input#billing_city' ).val('');
}
if (response.code == 200) {
var info = response.data;
noti.css('display','none');
noti.remove();
}
$('.loading').css('display','none');
}else{
$.ajax({
url: "<?=get_site_url()?>/wp-json/ahoadon/v1/taxcode/"+taxcode,
// data: {
// "taxcode": taxcode
// },
dataType: "json",
type: 'GET',
beforeSend: function () {
$('.loading').css('display','block');
},
success: function( response ) {
$('.loading').css('display','none');
// console.log(response);
if (response.status == 400) {
noti.text(response.message);
noti.css('display','block');
$( 'input#billing_company' ).val('');
$( 'input#billing_city' ).val('');
}
if (response.status == 200) {
var info = response.data;
noti.css('display','none');
noti.remove();
}
if ( info ) {
// $( 'input#_billing_first_name' ).val( info.Title );
// $( 'input#_billing_last_name' ).val( info.billing_last_name );
$( 'input#billing_company' ).val( info.Title );
// $( 'input#_billing_address_1' ).val( info.billing_address_1 );
// $( 'input#_billing_address_2' ).val( info.billing_address_2 );
$( 'input#billing_city' ).val( info.TinhThanhTitle );
// $( '#_billing_country' ).val( info.billing_country );
// $( 'input#_billing_state' ).val( info.billing_state );
// $( 'input#_billing_email' ).val( info.billing_email );
// $( 'input#_billing_phone' ).val( info.billing_phone );
// $( 'input#_billing_vat' ).val( info.billing_vat );
}
// $( '.edit_address' ).unblock();
},
error: function (xhr, ajaxOptions, thrownError) {
noti.text('Mã số thuế không hợp lệ');
noti.css('display','block');
$('.loading').css('display','none');
}
});
if ( info ) {
// $( 'input#_billing_first_name' ).val( info.Title );
// $( 'input#_billing_last_name' ).val( info.billing_last_name );
$( 'input#billing_company' ).val( info.Title );
// $( 'input#_billing_address_1' ).val( info.billing_address_1 );
// $( 'input#_billing_address_2' ).val( info.billing_address_2 );
$( 'input#billing_city' ).val( info.TinhThanhTitle );
// $( '#_billing_country' ).val( info.billing_country );
// $( 'input#_billing_state' ).val( info.billing_state );
// $( 'input#_billing_email' ).val( info.billing_email );
// $( 'input#_billing_phone' ).val( info.billing_phone );
// $( 'input#_billing_vat' ).val( info.billing_vat );
}
$( '.edit_address' ).unblock();
}
});
});
});
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment