484 lines
14 KiB
PHP
484 lines
14 KiB
PHP
<?php if ( ! defined( 'ABSPATH' ) ) {
|
|
exit;
|
|
} /* Exit if accessed directly */ ?>
|
|
<div class="dhl-package">
|
|
<?php
|
|
$key = 'dhl_product';
|
|
$args = array(
|
|
'label' => __( 'Usługa DHL', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_product_' . $id,
|
|
'type' => 'select',
|
|
'options' => WPDesk_WooCommerce_DHL::get_products(),
|
|
'input_class' => array( 'dhl-product' ),
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_product ) ) {
|
|
$value = $dhl_product;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
|
|
?>
|
|
<?php
|
|
$security = wp_create_nonce( 'woocommerce-dhl' );
|
|
|
|
if ( $dhl_product == 'parcelshop' ) {
|
|
$service_points = array();
|
|
$service_points = $all_servicepoints;
|
|
if ( ! $valid_service_point ) {
|
|
foreach ( $user_selected_service_point as $key => $value ) {
|
|
$service_points[ $key ] = $value;
|
|
}
|
|
}
|
|
?>
|
|
<div class="dhl-parcelshop">
|
|
<hr/>
|
|
<?php
|
|
$key = 'dhl_parcelshop';
|
|
$args = array(
|
|
'label' => __( 'Punkt odbioru', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_parcelshop_' . $id,
|
|
'type' => 'select',
|
|
'options' => $service_points,
|
|
'input_class' => array( 'dhl-parcelshop' ),
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_parcelshop ) ) {
|
|
$value = $dhl_parcelshop;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
</div>
|
|
<?php
|
|
}
|
|
?>
|
|
<hr/>
|
|
<div class="dhl_package_data">
|
|
<h4><?php echo sprintf( __( 'Paczka %s', 'woocommerce-dhl' ), 1 ); ?></h4>
|
|
<?php
|
|
$key = 'dhl_package_type';
|
|
$args = array(
|
|
'label' => __( 'Typ', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_package_type_' . $id,
|
|
'type' => 'select',
|
|
'options' => WPDesk_WooCommerce_DHL::get_package_types(),
|
|
'input_class' => array( 'dhl-package-type' ),
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_package_type ) ) {
|
|
$value = $dhl_package_type;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
|
|
<?php
|
|
$key = 'dhl_package_nonstandard';
|
|
$args = array(
|
|
'label' => __( 'Przesyłka niestandardowa (NST)', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_package_nonstandard_' . $id,
|
|
'type' => 'checkbox',
|
|
'input_class' => array( 'dhl-package-nonstandard' ),
|
|
);
|
|
|
|
$value = isset( $dhl_package_nonstandard ) ? $dhl_package_nonstandard : ( isset( $settings['package_nonstandard'] ) && $settings['package_nonstandard'] === 'yes' ? 1 : 0 );
|
|
|
|
if ( $disabled ) {
|
|
$args['input_class'][] = 'dhl-disabled';
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<div class="dhl-weight">
|
|
<?php
|
|
$key = 'dhl_package_weight';
|
|
$args = array(
|
|
'label' => __( 'Waga [kg]', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_package_weight_' . $id,
|
|
'type' => 'number',
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_package_weight ) ) {
|
|
$value = $dhl_package_weight;
|
|
} else {
|
|
$value = $settings['package_weight'];
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
</div>
|
|
<div class="dhl-dimensions">
|
|
<label><?php _e( 'Wymiary (dł / sz / wys) [cm]' ); ?></label>
|
|
<?php
|
|
$key = 'dhl_package_width';
|
|
$args = array(
|
|
'type' => 'number',
|
|
'id' => 'dhl_package_width_' . $id,
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_package_width ) ) {
|
|
$value = $dhl_package_width;
|
|
} else {
|
|
$value = $settings['package_width'];
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_package_length';
|
|
$args = array(
|
|
'label' => '/',
|
|
'type' => 'number',
|
|
'id' => 'dhl_package_length_' . $id,
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_package_length ) ) {
|
|
$value = $dhl_package_length;
|
|
} else {
|
|
$value = $settings['package_length'];
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_package_height';
|
|
$args = array(
|
|
'label' => '/',
|
|
'type' => 'number',
|
|
'id' => 'dhl_package_height_' . $id,
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_package_height ) ) {
|
|
$value = $dhl_package_height;
|
|
} else {
|
|
$value = $settings['package_height'];
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
</div>
|
|
</div>
|
|
<hr/>
|
|
<?php $count_additional = 1; ?>
|
|
<?php if ( isset( $additional_packages ) ) : ?>
|
|
<?php foreach ( $additional_packages as $additional_key => $additional_package ) : ?>
|
|
<?php $count_additional ++; ?>
|
|
<?php $additional_package_label = sprintf( __( 'Paczka %s', 'woocommerce-dhl' ), $count_additional ); ?>
|
|
<?php include( 'order-metabox-additional-package.php' ); ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
<?php if ( ! $disabled ) : ?>
|
|
<p id="dhl_add_package_<?php echo $id; ?>">
|
|
<a data-id="<?php echo $id; ?>" data-count_additional="<?php echo $count_additional; ?>"
|
|
class="button dhl-button dhl-button-add-package"><?php _e( 'Dodaj paczkę', 'woocommerce-dhl' ); ?></a>
|
|
<span class="dhl-spinner spinner shipping-spinner"></span>
|
|
</p>
|
|
<hr/>
|
|
<div class="dhl_additional_package_template" id="dhl_additional_package_template_<?php echo $id; ?>"
|
|
style="display: none;">
|
|
<?php $additional_key = '_additional_key_'; ?>
|
|
<?php $count_additional = '_count_additional_'; ?>
|
|
<?php $additional_package_label = __( 'Nowa paczka', 'woocommerce-dhl' ); ?>
|
|
<?php include( 'order-metabox-additional-package.php' ); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php
|
|
$key = 'dhl_shipment_date';
|
|
$args = array(
|
|
'label' => __( 'Data wysyłki', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_shipment_date_' . $id,
|
|
'type' => 'select',
|
|
'options' => $shipment_date_options,
|
|
);
|
|
$value = $shipment_date_default;
|
|
if ( isset( $dhl_shipment_date ) ) {
|
|
$value = $dhl_shipment_date;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['options'] = array( $dhl_shipment_date => $dhl_shipment_date );
|
|
$value = $dhl_shipment_date;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_insurance';
|
|
$args = array(
|
|
'label' => __( 'Ubezpieczenie', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_insurance_' . $id,
|
|
'type' => 'checkbox',
|
|
'input_class' => array( 'dhl-insurance' ),
|
|
);
|
|
$value = '0';
|
|
if ( isset( $dhl_insurance ) ) {
|
|
$value = $dhl_insurance;
|
|
} else {
|
|
$value = $settings['insurance'] ?? '0';
|
|
}
|
|
if ( $disabled ) {
|
|
$args['input_class'][] = 'dhl-disabled';
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_insurance_value';
|
|
$args = array(
|
|
'label' => __( 'Kwota ubezpieczenia', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_insurance_value_' . $id,
|
|
'type' => 'number',
|
|
'class' => array( 'dhl-insurance-value' ),
|
|
'custom_attributes' => array(
|
|
'min' => 0,
|
|
'step' => '0.01',
|
|
)
|
|
);
|
|
$value = '';
|
|
if ( isset( $dhl_insurance_value ) ) {
|
|
$value = $dhl_insurance_value;
|
|
} else {
|
|
$value = $order->get_total();
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes']['disabled'] = 'disabled';
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_cod';
|
|
$args = array(
|
|
'label' => __( 'Pobranie', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_cod_' . $id,
|
|
'type' => 'checkbox',
|
|
'input_class' => array( 'dhl-cod' ),
|
|
);
|
|
$value = '0';
|
|
if ( isset( $dhl_cod ) ) {
|
|
$value = $dhl_cod;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['input_class'][] = 'dhl-disabled';
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_cod_value';
|
|
$args = array(
|
|
'label' => __( 'Kwota pobrania', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_cod_value_' . $id,
|
|
'type' => 'number',
|
|
'class' => array( 'dhl-cod-value' ),
|
|
'custom_attributes' => array(
|
|
'min' => 0,
|
|
'step' => '0.01',
|
|
)
|
|
);
|
|
if ( 'PL' !== $order->get_shipping_country() ) {
|
|
$args['description'] = __( 'Uwaga! Dla przesyłek zagranicznych kwota pobrania jest wyrażona w lokalnej walucie odbiorcy przesyłki!', 'woocommerce-dhl' );
|
|
}
|
|
$value = '';
|
|
if ( isset( $dhl_cod_value ) ) {
|
|
$value = $dhl_cod_value;
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes']['disabled'] = 'disabled';
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<p class="form-row">
|
|
<label for="dhl_services_<?php echo $id; ?>">Usługi dodatkowe</label>
|
|
<span class="woocommerce-input-wrapper">
|
|
<select <?php disabled( $disabled, true ); ?> id="dhl_services_<?php echo $id; ?>" name="dhl_services" multiple
|
|
style="width: 100%;"
|
|
class="wc-enhanced-select dhl_services">
|
|
<?php foreach ( WPDesk_WooCommerce_DHL::get_services() as $service_id => $service_name ) : ?>
|
|
<option <?php selected( in_array( $service_id, $dhl_services ), true ); ?> value="<?php echo esc_attr( $service_id ); ?>"><?php echo $service_name; ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</span>
|
|
</p>
|
|
<?php
|
|
$key = 'dhl_content';
|
|
$args = array(
|
|
'label' => __( 'Zawartość', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_content_' . $id,
|
|
'type' => 'text',
|
|
);
|
|
if ( isset( $dhl_content ) ) {
|
|
$value = $dhl_content;
|
|
} elseif ( isset( $settings ) && isset( $settings['package_contents'] ) ) {
|
|
$value = $settings['package_contents'];
|
|
} else {
|
|
$value = '';
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php
|
|
$key = 'dhl_comment';
|
|
$args = array(
|
|
'label' => __( 'Komentarz', 'woocommerce-dhl' ),
|
|
'id' => 'dhl_comment_' . $id,
|
|
'type' => 'text',
|
|
);
|
|
|
|
if ( isset( $dhl_comment ) ) {
|
|
$value = $dhl_comment;
|
|
} else {
|
|
if ( isset( $settings ) && isset( $settings['package_comment'] ) ) {
|
|
$value = $settings['package_comment'];
|
|
$value = str_replace( '[order_number]', $order->get_order_number(), $value );
|
|
$value = str_replace( '[shop_name]', get_bloginfo( 'name' ), $value );
|
|
$value = str_replace( '[shop_url]', home_url(), $value );
|
|
} else {
|
|
$value = '';
|
|
}
|
|
}
|
|
if ( $disabled ) {
|
|
$args['custom_attributes'] = array( 'disabled' => 'disabled' );
|
|
}
|
|
woocommerce_form_field( $key, $args, $value );
|
|
?>
|
|
<?php /*
|
|
<?php if ( isset( $dhl_one_time_message ) && $dhl_one_time_message != '' ) : ?>
|
|
<p class="dhl_error">
|
|
<?php echo $dhl_one_time_message; ?>
|
|
</p>
|
|
<?php endif; ?>
|
|
<?php if ( isset( $dhl_status ) && $dhl_status == 'error' ) : ?>
|
|
<p class="dhl_error">
|
|
<?php echo $dhl_message; ?>
|
|
</p>
|
|
<?php endif; ?>
|
|
*/ ?>
|
|
<?php if ( isset( $dhl_status ) && $dhl_status == 'ok' ) : ?>
|
|
<p>
|
|
<?php _e( 'Przesyłka: ', 'woocommerce-dhl' ); ?> <a target="_blank"
|
|
href="<?php echo $tracking_url; ?>"><?php echo $dhl_package_number; ?></a>
|
|
</p>
|
|
<p>
|
|
<a target="_blank" href='<?php echo $label_url; ?>' data-id="<?php echo $id; ?>"
|
|
class="button button-primary dhl-button"><?php _e( 'Pobierz etykietę', 'woocommerce-dhl' ); ?></a>
|
|
<span class="spinner dhl-spinner shipping-spinner"></span>
|
|
<a data-id="<?php echo $id; ?>"
|
|
class="dhl-button dhl-button-delete-created button-shipping"><?php _e( 'Anuluj', 'woocommerce-dhl' ); ?></a>
|
|
</p>
|
|
<?php endif; ?>
|
|
<?php if ( $label_avaliable ) : ?>
|
|
<?php if ( apply_filters( 'flexible_printing', false ) ) : ?>
|
|
<p>
|
|
<?php echo apply_filters( 'flexible_printing_print_button', '', 'dhl',
|
|
array(
|
|
'content' => 'print',
|
|
'id' => $dhl_package_number,
|
|
'icon' => true,
|
|
'label' => __( 'Drukuj na: %s', 'woocommerce-dhl' ),
|
|
'data' => array(
|
|
'shippment_id' => $id,
|
|
'dhl_package_number' => $dhl_package_number,
|
|
),
|
|
)
|
|
); ?>
|
|
</p>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
<?php if ( ! $disabled ) : ?>
|
|
<p>
|
|
<button data-id="<?php echo $id; ?>"
|
|
class="button button-primary dhl-button dhl-button-create button-shipping"><?php _e( 'Utwórz', 'woocommerce-dhl' ); ?></button>
|
|
<button data-id="<?php echo $id; ?>"
|
|
class="button dhl-button dhl-button-save button-shipping"><?php _e( 'Zapisz', 'woocommerce-dhl' ); ?></button>
|
|
<span class="spinner dhl-spinner shipping-spinner"></span>
|
|
</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<script type="text/javascript">
|
|
|
|
jQuery( document ).ready( function ( $ ) {
|
|
const {__} = wp.i18n;
|
|
|
|
function matchStart( params, data ) {
|
|
if ( $.trim( params.term ) === '' ) {
|
|
return data;
|
|
}
|
|
|
|
if ( typeof data.children === 'undefined' ) {
|
|
return null;
|
|
}
|
|
|
|
var term = $.trim( params.term ).replace( /,/g, "" ).split( " " );
|
|
var str_pattern = term.join( '.+' );
|
|
var regex = new RegExp( '(' + str_pattern + ')', "gi" );
|
|
var filteredChildren = [];
|
|
$.each( data.children, function ( idx, child ) {
|
|
if ( regex.test( child.text ) ) {
|
|
filteredChildren.push( child );
|
|
}
|
|
} );
|
|
|
|
if ( filteredChildren.length ) {
|
|
var modifiedData = $.extend( {}, data, true );
|
|
modifiedData.children = filteredChildren;
|
|
return modifiedData;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
var _dhl_select = jQuery( '#dhl_parcelshop_<?php echo $id; ?>' );
|
|
var containerClass = 'dhl-parcelshop-select-container';
|
|
var options = {
|
|
containerCssClass: containerClass,
|
|
matcher: matchStart
|
|
};
|
|
|
|
options = {
|
|
containerCssClass: containerClass,
|
|
minimumInputLength: 3,
|
|
escapeMarkup: function ( markup ) {
|
|
return markup;
|
|
},
|
|
placeholder: __( 'Wpisz miasto lub miasto, ulica.', 'woocommerce-dhl' ), language: {
|
|
inputTooShort: function ( args ) {
|
|
var remainingChars = args.minimum - args.input.length;
|
|
var minimumChars = __( 'Wpisz minimum % znaki.', 'woocommerce-dhl' );
|
|
return minimumChars.replace( "%", remainingChars )
|
|
}, loadingMore: function () {
|
|
return __( 'Więcej...', 'woocommerce-dhl' )
|
|
}, noResults: function () {
|
|
return __( 'Brak punktów odbioru.', 'woocommerce-dhl' )
|
|
}, searching: function () {
|
|
return __( 'Szukam punktów odbioru...', 'woocommerce-dhl' )
|
|
}, errorLoading: function () {
|
|
return __( 'Wyszukiwanie w toku...', 'woocommerce-dhl' )
|
|
}
|
|
}
|
|
};
|
|
if ( $.fn.selectWoo ) {
|
|
_dhl_select.selectWoo( options );
|
|
} else if ( $.fn.select2 ) {
|
|
_dhl_select.select2( options );
|
|
}
|
|
|
|
dhl_init();
|
|
} )
|
|
</script>
|