first commit

This commit is contained in:
2024-07-15 11:28:08 +02:00
commit f52d538ea5
21891 changed files with 6161164 additions and 0 deletions

View File

@@ -0,0 +1,113 @@
<?php
class Easypack_checkout_validator
{
/**
* @var WC_Checkout
*/
private $wc_checkout;
public function __construct()
{
add_action('woocommerce_after_checkout_validation', array($this, 'validate_phone_number_uk'), 10, 2);
add_action('woocommerce_checkout_init', array($this, 'checkout_init'), 10);
}
/**
* @param WC_Checkout $instance
*/
public function checkout_init($instance)
{
$this->wc_checkout = $instance;
}
/**
* @param array $data
* @param WP_Error $errors
*/
public function validate_phone_number_uk($data, $errors)
{
if ('gb' !== get_option('easypack_api_country')) {
return;
}
$checkout = WC_Checkout::instance();
foreach ($checkout->get_checkout_fields() as $fieldset_key => $fieldset) {
if ($this->maybe_skip_fieldset($fieldset_key, $data)) {
continue;
}
foreach ($fieldset as $key => $field) {
if ( ! isset($data[$key])) {
continue;
}
$required = ! empty($field['required']);
$format = array_filter(isset($field['validate']) ? (array)$field['validate'] : array());
$field_label = isset($field['label']) ? $field['label'] : '';
switch ($fieldset_key) {
case 'shipping' :
/* translators: %s: field name */
$field_label = sprintf(__('Shipping %s', 'woocommerce'), $field_label);
break;
case 'billing' :
/* translators: %s: field name */
$field_label = sprintf(__('Billing %s', 'woocommerce'), $field_label);
break;
}
if (in_array('phone', $format)) {
if (false === $this->is_uk_phone($data[$key])) {
$errors->add('validation', sprintf(__('Please enter a valid UK phone number.', 'woocommerce'),
'<strong>' . esc_html($field_label) . '</strong>'));
}
}
}
}
}
/**
* @param string $phone
*
* @return bool
*
*/
private function is_uk_phone($phone)
{
$regex = "/^([0-9]{10,11})$/";
$cleaned_input = preg_replace('/\D/', '', (int)$phone); // leave only numbers
//var_dump($cleaned_input);die;
if (preg_match($regex, $cleaned_input)) {
return true;
}
return false;
}
/**
* See if a fieldset should be skipped.
*
* @since 3.0.0
*
* @param string $fieldset_key
* @param array $data
*
* @return bool
*/
protected function maybe_skip_fieldset($fieldset_key, $data)
{
if ('shipping' === $fieldset_key && ( ! $data['ship_to_different_address'] || ! WC()->cart->needs_shipping_address())) {
return true;
}
if ('account' === $fieldset_key && (is_user_logged_in() || ( ! $this->wc_checkout->is_registration_required() && empty($data['createaccount'])))) {
return true;
}
return false;
}
}
new Easypack_checkout_validator();

View File

@@ -0,0 +1,341 @@
<?php
/**
* EasyPack Shipping Method Cross Border Courier
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'EasyPack_Shippng_Cross_Border_Courier' ) ) {
class EasyPack_Shippng_Cross_Border_Courier extends EasyPack_Shippng_Cross_Border_Parcel_Machines {
/**
* Constructor for shipping class
*
* @access public
* @return void
*/
public function __construct() {
//$this->id = 'easypack_cross_border_courier';
//$this->method_title = __( 'Cross Border Courier', EasyPack::$text_domain );
//$this->init();
//dd_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
/**
* Init your settings
*
*
* @access public
* @return void
*/
function init() {
parent::init();
remove_action( 'woocommerce_review_order_after_shipping', array( $this, 'woocommerce_review_order_after_shipping') );
remove_action( 'woocommerce_checkout_update_order_meta', array( $this, 'woocommerce_checkout_update_order_meta') );
remove_action( 'woocommerce_checkout_process', array($this, 'woocommerce_checkout_process' ) );
}
public function rate_sort( $a, $b ) {
return strcmp( $a['country_name'], $b['country_name'] );
}
public function generate_rates_html( $key, $data )
{
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
ob_start();
$routes = CrossBorder_API()->me_routes();
$parcel_routes = array();
foreach ( $routes as $route ) {
if ( strtoupper( $route['recipient_country_code'] ) != strtoupper( str_replace( 'test-', '', get_option( 'easypack_api_country', 'pl' ) ) ) ) {
foreach ( $route['routes'] as $method ) {
if ( $method['recipient_method'] == 'ToDoor' ) {
$parcel_routes[$route['recipient_country_code']] = $route['recipient_country_code'];
}
}
}
}
foreach ( $rates as $country => $rate ) {
if ( isset( $parcel_routes[$country] ) ) {
unset( $parcel_routes[$country] );
}
else {
unset( $rates[$country] );
}
}
foreach ( $parcel_routes as $parcel_route ) {
$rates[$parcel_route] = array( 'kg_1' => '', 'kg_2' => '', 'kg_5' => '', 'kg_10' => '', 'kg_15' => '', 'kg_20' => '' );
}
$countries = WC()->countries->get_countries();
foreach ( $rates as $country => $rate ) {
$rates[$country]['country_name'] = $countries[$country];
$rates[$country]['country_code'] = $country;
}
// remove Poland
unset($rates['PL']);
usort( $rates, array( $this, 'rate_sort' ) );
include( 'views/html-rates-cross-border-courier.php' );
return ob_get_clean();
}
public function init_form_fields() {
$bank_accounts = array();
//$bacs = new WC_Gateway_BACS();
//$accounts = $bacs->account_details;
$accounts = get_option( 'woocommerce_bacs_accounts', array() );
foreach ( $accounts as $account )
{
$bank_accounts[$account['account_number']] = $account['account_number'] . ' ' . $account['bank_name'];
}
$settings = array(
array(
'title' => __( 'General settings', EasyPack::$text_domain ),
'type' => 'title',
'description' => '',
'id' => 'section_general_settings',
),
'enabled' => array(
'title' => __( 'Enable/disable', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Enable this shipping metod', EasyPack::$text_domain ),
'default' => 'no',
),
'title' => array(
'title' => __( 'Method title', EasyPack::$text_domain ),
'type' => 'text',
'default' => __( 'Cross Border Courier', EasyPack::$text_domain ),
'desc_tip' => false
),
'free_shipping_cost' => array(
'title' => __('Free shipping', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
'default' => '',
'desc_tip' => __('Enter the amount of the contract, from which shipping will be free (does not include virtual products).', EasyPack::$text_domain ),
'placeholder' => '0.00'
),
'flat_rate' => array(
'title' => __( 'Flat rate', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Set a flat-rate shipping fee for the entire order.', EasyPack::$text_domain ),
'class' => 'easypack_flat_rate',
'default' => 'yes',
),
'cost_per_order' => array(
'title' => __( 'Cost per order', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
'class' => 'easypack_cost_per_order',
'default' => '',
'desc_tip' => __( 'Set a flat-rate shipping for all orders.', EasyPack::$text_domain ),
'placeholder' => '0.00'
),
'rates' => array(
'title' => __('Rates table', EasyPack::$text_domain ),
'type' => 'rates',
'default' => '',
'desc_tip' => 'The default pricing information for your account is below the edit field. You can edit and set your own prices that will be seen when the customer is placing the order.',
),
);
$this->form_fields = $settings;
}
/**
* @param unknown $package
*
*/
public function calculate_shipping_table_rate( $package ) {
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
$cart = WC()->cart;
$value = 0;
$weight = $this->package_weight( $package['contents'] );
foreach ( $rates as $country => $rate ) {
$cost = false;
if ( $package['destination']['country'] == $country ) {
if ( $weight <= 25 ) {
if ( $weight <= 1 ) {
if ( isset( $rate['kg_1'] ) && trim( $rate['kg_1'] ) != '' ) {
$cost = floatval( $rate['kg_1'] );
}
}
else if ( $weight <= 2 ) {
if ( isset( $rate['kg_2'] ) && trim( $rate['kg_2'] ) != '' ) {
$cost = floatval( $rate['kg_2'] );
}
}
else if ( $weight <= 5 ) {
if ( isset( $rate['kg_5'] ) && trim( $rate['kg_5'] ) != '' ) {
$cost = floatval( $rate['kg_5'] );
}
}
else if ( $weight <= 10 ) {
if ( isset( $rate['kg_10'] ) && trim( $rate['kg_10'] ) != '' ) {
$cost = floatval( $rate['kg_10'] );
}
}
else if ( $weight <= 15 ) {
if ( isset( $rate['kg_15'] ) && trim( $rate['kg_15'] ) != '' ) {
$cost = floatval( $rate['kg_15'] );
}
}
else if ( $weight <= 20 ) {
if ( isset( $rate['kg_20'] ) && trim( $rate['kg_20'] ) != '' ) {
$cost = floatval( $rate['kg_20'] );
}
}
else if ( $weight <= 25 ) {
if ( isset( $rate['kg_25'] ) && trim( $rate['kg_25'] ) != '' ) {
$cost = floatval( $rate['kg_25'] );
}
}
}
}
if ( $cost !== false )
{
$add_rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $cost,
);
$this->add_rate( $add_rate );
return;
}
}
}
public function save_post( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['easypack_box_data_crossborder_courier'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['easypack_box_data_crossborder_courier'], 'easypack_box_data_crossborder_courier' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
$status = get_post_meta( $post_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
if ( $status == 'new' ) {
$parcels = $_POST['parcel'];
$easypack_pacels = array();
foreach ( $parcels as $parcel )
{
$parcel_data = array( 'package_weight' => $parcel['weight'] );
$parcel_data['package_width'] = $parcel['width'];
$parcel_data['package_height'] = $parcel['height'];
$parcel_data['package_length'] = $parcel['length'];
$easypack_pacels[] = $parcel_data;
}
update_post_meta( $post_id, '_easypack_parcels', $easypack_pacels );
$easypack_send_method = $_POST['easypack_send_method'];
update_post_meta( $post_id, '_easypack_send_method', $easypack_send_method );
}
}
public function add_meta_boxes( $post_type, $post ) {
if ( $post->post_type == 'shop_order' )
{
$order = wc_get_order( $post->ID );
if ( $order->has_shipping_method($this->id) ) {
add_meta_box( 'easypack_parcel_machines', __('InPost', EasyPack::$text_domain ) . $this->get_logo(), array( $this, 'order_metabox' ), 'shop_order', 'side', 'default' );
}
}
}
public function order_metabox( $post ) {
self::order_metabox_content( $post );
}
public static function order_metabox_content( $post, $output = true ) {
if ( ! $output ) ob_start();
$order_id = $post->ID;
$order = wc_get_order( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
$parcel_machines = CrossBorder_API()->machines_options( $order->shipping_country );
$parcel_machine_id = get_post_meta( $post->ID, '_parcel_machine_id', true );
$parcels = get_post_meta( $post->ID, '_easypack_parcels', true );
$package_weights = EasyPack()->get_package_weights_courier();
if ( $parcels == '' ) {
$order_weight = EasyPack_Helper()->get_order_weight( $order );
$weight = EasyPack_Helper()->get_weight_option( $order_weight, $package_weights );
$parcels = array();
$parcel = array( 'package_weight' => $weight );
$parcel['package_width'] = get_option( 'easypack_package_width_courier', 60 );
$parcel['package_height'] = get_option( 'easypack_package_height_courier', 40 );
$parcel['package_length'] = get_option( 'easypack_package_length_courier', 40 );
$parcels[] = $parcel;
}
$send_methods = array( 'parcel_machine' => __( 'Parcel locker', EasyPack::$text_domain ), 'courier' => __( 'Courier', EasyPack::$text_domain ) );
$send_method = get_post_meta( $post->ID, '_easypack_send_method', true );
if ( $send_method == '' ) {
$send_method = get_option( 'easypack_default_send_method', 'parcel_machine' );
}
$stickers_url = site_url('?easypack_download=1&easypack_parcel_machines_stickers=1&cross_border=1&order_id=' . $order_id . '&security=' . wp_create_nonce( 'easypack_nonce' ) );
$tracking_url = false;
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url('pl-cb');
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['crossborder_data']['tracking_number'] . ',';
}
$tracking_url = trim( $tracking_url, ',' );
}
$disabled = false;
if ( $status != 'new' ) $disabled = true;
echo '<input id="easypack_status" type="hidden" name="easypack_status" value="' . $status . '">';
include( 'views/html-order-matabox-crossborder-courier.php' );
wp_nonce_field( 'easypack_box_data_crossborder_courier', 'easypack_box_data_crossborder_courier' );
if ( ! $output )
{
$out = ob_get_clean();
return $out;
}
}
public static function ajax_create_package( $courier = true ) {
parent::ajax_create_package( $courier );
}
}
}

View File

@@ -0,0 +1,690 @@
<?php
/**
* EasyPack Shipping Method Cross Border Parcel Machines
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'EasyPack_Shippng_Cross_Border_Parcel_Machines' ) ) {
class EasyPack_Shippng_Cross_Border_Parcel_Machines extends EasyPack_Shippng_Parcel_Machines {
/**
* Constructor for shipping class
*
* @access public
* @return void
*/
public function __construct() {
//$this->id = 'easypack_cross_border_parcel_machines';
//$this->method_title = __( 'Cross Border Parcel Locker', EasyPack::$text_domain );
//$this->init();
//add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
//add_action( 'wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 1 );
}
public function admin_options()
{
?>
<table class="form-table">
<?php $this->generate_settings_html(); ?>
</table>
<script type="text/javascript">
function display_rates() {
if ( jQuery('.easypack_flat_rate').prop('checked') ) {
jQuery('.easypack_cost_per_order').closest('tr').css('display','table-row');
jQuery('.easypack_rates').closest('tr').css('display','none');
}
else {
jQuery('.easypack_cost_per_order').closest('tr').css('display','none');
jQuery('.easypack_rates').closest('tr').css('display','table-row');
}
}
jQuery('.easypack_flat_rate').change(function() {
display_rates();
});
display_rates();
</script>
<?php
}
public function generate_rates_html( $key, $data )
{
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
ob_start();
$routes = CrossBorder_API()->me_routes();
$parcel_routes = array();
foreach ( $routes as $route ) {
if ( strtoupper( $route['recipient_country_code'] ) != strtoupper( str_replace( 'test-', '', get_option( 'easypack_api_country', 'pl' ) ) ) ) {
foreach ( $route['routes'] as $method ) {
if ( $method['recipient_method'] == 'ToParcelMachine' ) {
$parcel_routes[$route['recipient_country_code']] = $route['recipient_country_code'];
}
}
}
}
foreach ( $rates as $country => $rate ) {
if ( isset( $parcel_routes[$country] ) ) {
unset( $parcel_routes[$country] );
}
else {
unset( $rates[$country] );
}
}
foreach ( $parcel_routes as $parcel_route ) {
$rates[$parcel_route] = array( 'kg_1' => '', 'kg_2' => '', 'kg_5' => '', 'kg_10' => '', 'kg_15' => '', 'kg_20' => '' );
}
$countries = WC()->countries->get_countries();
include( 'views/html-rates-cross-border-parcel-machines.php' );
return ob_get_clean();
}
public function init_form_fields() {
$bank_accounts = array();
//$bacs = new WC_Gateway_BACS();
//$accounts = $bacs->account_details;
$accounts = get_option( 'woocommerce_bacs_accounts', array() );
foreach ( $accounts as $account )
{
$bank_accounts[$account['account_number']] = $account['account_number'] . ' ' . $account['bank_name'];
}
$settings = array(
array(
'title' => __( 'General settings', EasyPack::$text_domain ),
'type' => 'title',
'description' => '',
'id' => 'section_general_settings',
),
'enabled' => array(
'title' => __( 'Enable/disable', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Enable this shipping metod', EasyPack::$text_domain ),
'default' => 'no',
),
'title' => array(
'title' => __( 'Method title', EasyPack::$text_domain ),
'type' => 'text',
'default' => __( 'Cross Border Parcel Locker', EasyPack::$text_domain ),
'desc_tip' => false
),
'free_shipping_cost' => array(
'title' => __('Free shipping', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
'default' => '',
'desc_tip' => __('Enter the amount of the contract, from which shipping will be free (does not include virtual products).', EasyPack::$text_domain ),
'placeholder' => '0.00'
),
'flat_rate' => array(
'title' => __( 'Flat rate', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Set a flat-rate shipping fee for the entire order.', EasyPack::$text_domain ),
'class' => 'easypack_flat_rate',
'default' => 'yes',
),
'cost_per_order' => array(
'title' => __( 'Cost per order', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
'class' => 'easypack_cost_per_order',
'default' => '',
'desc_tip' => __( 'Set a flat-rate shipping for all orders.', EasyPack::$text_domain ),
'placeholder' => '0.00'
),
'rates' => array(
'title' => __('Rates table', EasyPack::$text_domain ),
'type' => 'rates',
'default' => '',
'desc_tip' => 'The default pricing information for your account is below the edit field. You can edit and set your own prices that will be seen when the customer is placing the order.',
),
);
$this->form_fields = $settings;
}
/**
* @param unknown $package
*
*/
public function calculate_shipping_table_rate( $package ) {
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
$cart = WC()->cart;
$value = 0;
$weight = $this->package_weight( $package['contents'] );
foreach ( $rates as $country => $rate ) {
$cost = false;
if ( $package['destination']['country'] == $country ) {
if ( $weight <= 20 ) {
if ( $weight <= 1 ) {
if ( isset( $rate['kg_1'] ) && trim( $rate['kg_1'] ) != '' ) {
$cost = floatval( $rate['kg_1'] );
}
}
else if ( $weight <= 2 ) {
if ( isset( $rate['kg_2'] ) && trim( $rate['kg_2'] ) != '' ) {
$cost = floatval( $rate['kg_2'] );
}
}
else if ( $weight <= 5 ) {
if ( isset( $rate['kg_5'] ) && trim( $rate['kg_5'] ) != '' ) {
$cost = floatval( $rate['kg_5'] );
}
}
else if ( $weight <= 10 ) {
if ( isset( $rate['kg_10'] ) && trim( $rate['kg_10'] ) != '' ) {
$cost = floatval( $rate['kg_10'] );
}
}
else if ( $weight <= 15 ) {
if ( isset( $rate['kg_15'] ) && trim( $rate['kg_15'] ) != '' ) {
$cost = floatval( $rate['kg_15'] );
}
}
else if ( $weight <= 20 ) {
if ( isset( $rate['kg_20'] ) && trim( $rate['kg_20'] ) != '' ) {
$cost = floatval( $rate['kg_20'] );
}
}
}
}
if ( $cost !== false )
{
$add_rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $cost,
);
$this->add_rate( $add_rate );
return;
}
}
}
public function calculate_shipping( $package = array() ) {
$available = false;
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
foreach ( $rates as $country => $rate ) {
if ( $package['destination']['country'] == $country ) {
$available = true;
}
}
if ( $available ) {
if ( ! $this->calculate_shipping_free_shipping( $package ) ) {
if ( ! $this->calculate_shipping_flat( $package ) ) {
$this->calculate_shipping_table_rate( $package );
}
}
}
}
public function woocommerce_review_order_after_shipping() {
if ( in_array( $this->id, WC()->session->get('chosen_shipping_methods') ) ) {
$shipping_country = WC()->session->customer['shipping_country'];
if ( isset( $_REQUEST['country'] ) && trim( $_REQUEST['country'] ) != '' ) {
$shipping_country = $_REQUEST['country'];
}
if ( isset( $_REQUEST['s_country'] ) && trim( $_REQUEST['s_country'] ) != '' ) {
$shipping_country = $_REQUEST['s_country'];
}
$parcel_machines = CrossBorder_API()->machines_options( $shipping_country );
$args = array( 'parcel_machines' => $parcel_machines );
$args['parcel_machine_id'] = WC()->session->get( 'parcel_machine_id' );
$geowidget_src = false;
try {
$geowidget_keys = CrossBorder_API()->geowidget_keys();
$sheepla_api_key = $geowidget_keys['public_key'];
$geowidget_src = '//widget-xborder-inpost.sheepla.com/js/SheeplaLib.js';
$geowidget_css = '//widget-xborder-inpost.sheepla.com/css/SheeplaCrossBorder.css';
}
catch ( Exception $e ) {
}
$args['geowidget_src'] = $geowidget_src;
$args['geowidget_css'] = $geowidget_css;
$args['sheepla_api_key'] = $sheepla_api_key;
wc_get_template( 'checkout/crossborder-review-order-after-shipping.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
}
public function woocommerce_checkout_process() {
if ( in_array( $this->id, WC()->session->get('chosen_shipping_methods') ) ) {
if ( empty( $_POST['parcel_machine_id'] ) ) {
wc_add_notice( __( 'Parcel locker must be choosen.', EasyPack::$text_domain ), 'error' );
}
else {
WC()->session->set( 'parcel_machine_id', $_POST['parcel_machine_id'] );
}
}
}
public function woocommerce_checkout_update_order_meta( $order_id ) {
if ($_POST['parcel_machine_id']) {
update_post_meta($order_id, '_parcel_machine_id', esc_attr($_POST['parcel_machine_id']));
$weight = WC()->cart->cart_contents_weight;
update_post_meta( $order_id, '_cart_weight', $weight );
}
}
public function save_post( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['easypack_box_data_crossborder_parcel_machines'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['easypack_box_data_crossborder_parcel_machines'], 'easypack_box_data_crossborder_parcel_machines' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
$status = get_post_meta( $post_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
if ( $status == 'new' ) {
$parcel_machine_id = $_POST['parcel_machine_id'];
update_post_meta( $post_id, '_parcel_machine_id', $parcel_machine_id );
$parcels = $_POST['parcel'];
$easypack_pacels = array();
foreach ( $parcels as $parcel )
{
$parcel_data = array( 'package_weight' => $parcel['weight'] );
$parcel_data['package_width'] = $parcel['width'];
$parcel_data['package_height'] = $parcel['height'];
$parcel_data['package_length'] = $parcel['length'];
$easypack_pacels[] = $parcel_data;
}
update_post_meta( $post_id, '_easypack_parcels', $easypack_pacels );
$easypack_send_method = $_POST['easypack_send_method'];
update_post_meta( $post_id, '_easypack_send_method', $easypack_send_method );
}
}
public function add_meta_boxes( $post_type, $post ) {
if ( $post->post_type == 'shop_order' )
{
$order = wc_get_order( $post->ID );
if ( $order->has_shipping_method($this->id) ) {
add_meta_box( 'easypack_parcel_machines', __('InPost', EasyPack::$text_domain ) . $this->get_logo(), array( $this, 'order_metabox' ), 'shop_order', 'side', 'default' );
}
}
}
public function order_metabox( $post ) {
self::order_metabox_content( $post );
}
public static function order_metabox_content( $post, $output = true ) {
if ( ! $output ) ob_start();
$order_id = $post->ID;
$order = wc_get_order( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
$parcel_machines = CrossBorder_API()->machines_options( $order->shipping_country );
$parcel_machine_id = get_post_meta( $post->ID, '_parcel_machine_id', true );
$parcels = get_post_meta( $post->ID, '_easypack_parcels', true );
$package_weights = EasyPack()->get_package_weights_parcel_machines();
if ( $parcels == '' ) {
$order_weight = EasyPack_Helper()->get_order_weight( $order );
$weight = EasyPack_Helper()->get_weight_option( $order_weight, $package_weights );
$parcels = array();
$parcel = array( 'package_weight' => $weight );
$parcel['package_width'] = get_option( 'easypack_package_width', 64 );
$parcel['package_height'] = get_option( 'easypack_package_height', 41 );
$parcel['package_length'] = get_option( 'easypack_package_length', 38 );
$parcels[] = $parcel;
}
$send_methods = array( 'parcel_machine' => __( 'Parcel locker', EasyPack::$text_domain ), 'courier' => __( 'Courier', EasyPack::$text_domain ) );
$send_method = get_post_meta( $post->ID, '_easypack_send_method', true );
if ( $send_method == '' ) {
$send_method = get_option( 'easypack_default_send_method', 'parcel_machine' );
}
$stickers_url = site_url('?easypack_download=1&easypack_parcel_machines_stickers=1&cross_border=1&order_id=' . $order_id . '&security=' . wp_create_nonce( 'easypack_nonce' ) );
$tracking_url = false;
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url('pl-cb');
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['crossborder_data']['tracking_number'] . ',';
}
$tracking_url = trim( $tracking_url, ',' );
}
$disabled = false;
if ( $status != 'new' ) $disabled = true;
echo '<input id="easypack_status" type="hidden" name="easypack_status" value="' . $status . '">';
include( 'views/html-order-matabox-crossborder-parcel-machines.php' );
wp_nonce_field( 'easypack_box_data_crossborder_parcel_machines', 'easypack_box_data_crossborder_parcel_machines' );
if ( ! $output )
{
$out = ob_get_clean();
return $out;
}
}
public static function ajax_create_package( $courier = false ) {
return;
$ret = array( 'status' => 'ok' );
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$parcels = $_POST['parcels'];
$parcel_machine_id = '';
if ( isset( $_POST['parcel_machine_id'] ) ) {
$parcel_machine_id = $_POST['parcel_machine_id'];
}
$send_method = $_POST['send_method'];
$order_parcels = array();
$total_amount = 0;
foreach ( $parcels as $key => $parcel )
{
$country = strtoupper( str_replace( 'test-', '', get_option( 'easypack_api_country' ,'PL' ) ) );
$args = array();
$args['declared_weight'] = array( 'amount' => $parcel['weight'], 'unit' => 'kg' );
$args['declared_dimensions'] = array( 'unit' => 'cm' );
$args['declared_dimensions']['width'] = $parcel['width'];
$args['declared_dimensions']['height'] = $parcel['height'];
$args['declared_dimensions']['length'] = $parcel['length'];
if ( $courier ) {
update_option( 'easypack_package_width_courier', $parcel['width'] );
update_option( 'easypack_package_height_courier', $parcel['height'] );
update_option( 'easypack_package_length_courier', $parcel['length'] );
}
else {
update_option( 'easypack_package_width', $parcel['width'] );
update_option( 'easypack_package_height', $parcel['height'] );
update_option( 'easypack_package_length', $parcel['length'] );
}
$args['recipient'] = array();
$args['recipient']['country_code'] = $order->shipping_country;
$args['recipient']['email'] = $order->billing_email;
$args['recipient']['first_name'] = $order->shipping_first_name;
$args['recipient']['last_name'] = $order->shipping_last_name;
$args['recipient']['phone'] = $order->billing_phone;
if ( ! $courier ) {
$args['recipient']['pop'] = array( 'id' => $parcel_machine_id, 'size' => 'C' );
}
else {
$args['recipient']['address'] = array();
$args['recipient']['address']['zip_code'] = $order->shipping_postcode;
$args['recipient']['address']['street'] = $order->shipping_address_1;
$args['recipient']['address']['building_number'] = $order->shipping_address_2;
$args['recipient']['address']['flat_number'] = '';
$args['recipient']['address']['city'] = $order->shipping_city;
}
$args['sender'] = array();
if ( $send_method == 'parcel_machine' ) {
$sender_machine_id = false;
$sender_machine = CrossBorder_API()->get_machine_by_name( get_option( 'easypack_default_machine_id' ), $country );
if ( $sender_machine ) $sender_machine_id = $sender_machine['id'];
$args['sender']['pop'] = array( 'id' => $sender_machine_id, 'size' => 'C' );
}
else {
$args['sender']['address'] = array();
$args['sender']['address']['zip_code'] = get_option( 'easypack_sender_post_code' );
$args['sender']['address']['street'] = get_option( 'easypack_sender_city' );
$args['sender']['address']['building_number'] = get_option( 'easypack_sender_building_no' );
$args['sender']['address']['flat_number'] = get_option( 'easypack_sender_flat_no' );
$args['sender']['address']['city'] = get_option( 'easypack_sender_city' );
}
$args['sender']['country_code'] = $country;
$args['sender']['email'] = get_option( 'easypack_sender_email' );
$args['sender']['company_name'] = get_option( 'easypack_sender_company_name' );
$args['sender']['first_name'] = get_option( 'easypack_sender_first_name' );
$args['sender']['last_name'] = get_option( 'easypack_sender_last_name' );
$args['sender']['phone'] = get_option( 'easypack_sender_phone' );
$package_status = 'ReadyToBeSent';
try {
$crossborder_data = CrossBorder_API()->shipments($args);
if ( isset( $crossborder_data['id'] ) ) {
$package_data = CrossBorder_API()->shipment( $crossborder_data['id'] );
$package_status = $package_data['status']['code'];
$order_parcels[] = array(
'package_weight' => $parcel['weight'],
'package_width' => $parcel['width'],
'package_height' => $parcel['height'],
'package_length' => $parcel['length'],
'crossborder_data' => $package_data
);
}
else {
$ret['status'] = 'error';
$ret['message'] = '';
foreach ( $crossborder_data as $error ) {
$ret['message'] .= $error['message'] . ', ';
}
$ret['message'] = trim( $ret['message'] );
$ret['message'] = trim( $ret['message'], ',' );
break;
}
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] = __( 'There are some errors. Please fix it:', EasyPack::$text_domain ) . $e->getMessage();
break;
}
}
if ( $ret['status'] == 'ok' ) {
update_post_meta( $order_id, '_easypack_parcels', $order_parcels );
update_post_meta( $order_id, '_easypack_status', $package_status );
update_post_meta( $order_id, '_easypack_send_method', $send_method );
$ret['content'] = self::order_metabox_content( $post, false );
}
echo json_encode( $ret );
wp_die();
}
public static function ajax_processing() {
$ret = array( 'status' => 'ok' );
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
$package_status = 'Processing';
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
$package_data = CrossBorder_API()->shipment( $parcel['crossborder_data']['id'] );
$package_status = $package_data['status']['code'];
$easypack_parcels[$key]['crossborder_data'] = $package_data;
if ( $package_data['status']['code'] == 'Rejected' ) {
unset( $easypack_parcels[$key]['crossborder_data'] );
$ret['status'] = 'error';
$ret['message'] = CrossBorder_API()->translate_error( $package_data['status']['comments'] );
}
}
update_post_meta( $order_id, '_easypack_parcels', $easypack_parcels );
}
if ( $ret['status'] == 'ok' ) {
$order->add_order_note( __( 'Shipment created', EasyPack::$text_domain ), false);
update_post_meta( $order_id, '_easypack_status', $package_status );
$ret['content'] = self::order_metabox_content( $post, false );
}
else {
delete_post_meta( $order_id, '_easypack_status' );
$ret['content'] = self::order_metabox_content( $post, false );
}
echo json_encode( $ret );
wp_die();
}
public static function get_stickers() {
$nonce = $_GET['security'];
if ( ! wp_verify_nonce( $nonce, 'easypack_nonce' ) ) {
echo __( 'Security check - bad nonce!', EasyPack::$text_domain );
return;
}
$order_id = $_GET['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
$stickers = array();
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
try {
$sticker = CrossBorder_API()->pdf_label( $parcel['crossborder_data']['id'] );
$stickers[] = $sticker;
}
catch ( Exception $e ) {
echo $e->getMessage();
return;
}
}
}
if ( count( $stickers ) == 1 ) {
if ( isset( $stickers[0][0]['pdf_url'] ) && trim( $stickers[0][0]['pdf_url'] ) != '' ) {
header('Location: ' . $stickers[0][0]['pdf_url'] );
die();
}
}
else {
$file = EasyPack_Helper()->write_stickers_to_file( $stickers );
if ( $status == 'created' ) {
update_post_meta( $order_id, '_easypack_status', 'prepared' );
}
EasyPack_Helper()->get_file($file, __( 'stickers', EasyPack::$text_domain ) . '_' . $order->get_id() . '.pdf', 'application/pdf' );
}
}
function woocommerce_my_account_my_orders_actions( $actions, $order ) {
if ( $order->has_shipping_method($this->id) ) {
$status = get_post_meta( $order->id, '_easypack_status', true );
$tracking_url = false;
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url();
$parcels = get_post_meta( $order->id, '_easypack_parcels', true );
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['crossborder_data']['tracking_number'] . ',';
}
$tracking_url = trim( $tracking_url, ',' );
}
if ( $tracking_url ) {
$actions['easypack_tracking'] = array(
'url' => $tracking_url,
'name' => __( 'Track shipment', EasyPack::$text_domain )
);
}
}
return $actions;
}
function woocommerce_email_after_order_table( $order, $is_admin, $plain_text ) {
if ( $order->has_shipping_method($this->id) ) {
$status = get_post_meta( $order->id, '_easypack_status', true );
if ( $status != '' ) {
$tracking_url = false;
$package_numbers = '';
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url();
$parcels = get_post_meta( $order->id, '_easypack_parcels', true );
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['crossborder_data']['tracking_number'] . ',';
$package_numbers = $parcel['crossborder_data']['tracking_number'] . ', ';
}
$package_numbers = trim( trim ( $package_numbers ) , ',' );
$tracking_url = trim( $tracking_url, ',' );
}
if ( $tracking_url ) {
$args['tracking_url'] = $tracking_url;
$args['package_numbers'] = $package_numbers;
$args['logo'] = untrailingslashit( EasyPack()->getPluginUrl() ) . '/assets/images/logo/small/white.png';
if ( $plain_text ) {
wc_get_template( 'emails/plain/after-order-table.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
else {
wc_get_template( 'emails/after-order-table.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
}
}
}
}
function wp_enqueue_scripts() {
if ( is_checkout() ) {
$geowidget_src = '//widget-xborder-inpost.sheepla.com/js/SheeplaLib.js';
wp_enqueue_script(
'crossborder-geowidget',
$geowidget_src,
array( 'jquery' )
);
$geowidget_css = '//widget-xborder-inpost.sheepla.com/css/SheeplaCrossBorder.css';
wp_enqueue_style( 'crossborder-geowidget', $geowidget_css );
}
}
}
}

View File

@@ -0,0 +1,470 @@
<?php
/**
* EasyPack Shipping Method Parcel Machines COD
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'EasyPack_Shippng_Parcel_Machines_COD' ) ) {
class EasyPack_Shippng_Parcel_Machines_COD extends EasyPack_Shippng_Parcel_Machines {
/**
* Constructor for shipping class
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'easypack_parcel_machines_cod';
$this->method_title = __( 'InPost Locker 24/7 COD', EasyPack::$text_domain );
$this->init();
}
public function generate_rates_html( $key, $data )
{
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
$commission = '';
try {
$pricelists = EasyPack_API()->customer_pricelists();
$commission = floatval($pricelists['_embedded']['standard']['cod']['commission']);
}
catch ( Exception $e ) {
?>
<div class="error">
<p><?php echo $e->getMessage(); ?></p>
</div>
<?php
}
ob_start();
include( 'views/html-rates-cod.php' );
return ob_get_clean();
}
public function init_form_fields() {
$bank_accounts = array();
//$bacs = new WC_Gateway_BACS();
//$accounts = $bacs->account_details;
$accounts = get_option( 'woocommerce_bacs_accounts', array() );
foreach ( $accounts as $account )
{
if ( isset( $account['iban'] ) && $account['iban'] != '' ) {
$bank_accounts[$account['iban']] = $account['iban'] . ' ' . $account['bank_name'];
}
}
$settings = array(
array(
'title' => __( 'General settings', EasyPack::$text_domain ),
'type' => 'title',
'description' => '',
'id' => 'section_general_settings',
),
'enabled' => array(
'title' => __( 'Enable/disable', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Enable this shipping metod', EasyPack::$text_domain ),
'default' => 'no',
),
'title' => array(
'title' => __( 'Method title', EasyPack::$text_domain ),
'type' => 'text',
'default' => __( 'InPost Locker 24/7 COD', EasyPack::$text_domain ),
'custom_attributes' => array( 'required' => 'required' ),
'desc_tip' => false
),
/* RM: 11101
'bank_account' => array(
'title' => __( 'Bank account', EasyPack::$text_domain ),
'type' => 'select',
'desc_tip' => __( 'Select the account to which the cost of COD will be transferred. If the list is empty, add the account number in the Settings.', EasyPack::$text_domain ),
'class' => 'wc-enhanced-select1',
'custom_attributes' => array( 'required' => 'required' ),
'options' => $bank_accounts
),
*/
'free_shipping_cost' => array(
'title' => __('Free shipping', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array( 'step' => 'any', 'min' => '0' ),
'default' => '',
'desc_tip' => __('Enter the amount of the contract, from which shipping will be free (does not include virtual products).', EasyPack::$text_domain ),
'placeholder' => '0.00'
),
'flat_rate' => array(
'title' => __( 'Flat rate', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Set a flat-rate shipping fee for the entire order.', EasyPack::$text_domain ),
'class' => 'easypack_flat_rate',
'default' => 'yes',
),
'cost_per_order' => array(
'title' => __( 'Cost per order', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array( 'step' => 'any', 'min' => '0' ),
'class' => 'easypack_cost_per_order',
'default' => '',
'desc_tip' => 'Set a flat-rate shipping for all orders.',
'placeholder' => '0.00'
),
array(
'title' => __( 'Rates table', EasyPack::$text_domain ),
'type' => 'title',
'description' => '',
'id' => 'section_general_settings',
),
'based_on' => array(
'title' => __( 'Based on', EasyPack::$text_domain ),
'type' => 'select',
'desc_tip' => __( 'Select the method of calculating shipping cost. If the cost of shipping is to be calculated based on the weight of the cart and the products do not have a defined weight, the cost will be calculated incorrectly.', EasyPack::$text_domain ),
'class' => 'wc-enhanced-select easypack_based_on',
'options' => array(
'price' => __( 'Price', EasyPack::$text_domain ),
'weight' => __( 'Weight', EasyPack::$text_domain )
)
),
'rates' => array(
'title' => '',
'type' => 'rates',
'class' => 'easypack_rates',
'default' => '',
'desc_tip' => '',
),
);
$this->form_fields = $settings;
}
public function process_admin_options()
{
parent::process_admin_options();
EasyPack_API()->clear_cache();
/* RM 11101
$args = array();
$args['iban'] = $this->get_option( 'bank_account' );
try {
EasyPack_API()->update_customer( $args );
}
catch ( Exception $e ) {
WC_Admin_Settings::add_error( strip_tags( $e->getMessage() ) );
}
*/
}
public function woocommerce_checkout_update_order_meta( $order_id ) {
if ($_POST['parcel_machine_id']) {
update_post_meta($order_id, '_parcel_machine_id', esc_attr($_POST['parcel_machine_id']));
}
if ($_POST['parcel_machine_desc']) {
update_post_meta($order_id, '_parcel_machine_desc', esc_attr($_POST['parcel_machine_desc']));
}
}
public function save_post( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['easypack_box_data_parcel_machines_cod'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['easypack_box_data_parcel_machines_cod'], 'easypack_box_data_parcel_machines_cod' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
$status = get_post_meta( $post_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
if ( $status == 'new' ) {
$parcel_machine_id = $_POST['parcel_machine_id'];
$parcel_machine_desc = $_POST['parcel_machine_desc'];
update_post_meta( $post_id, '_parcel_machine_id', $parcel_machine_id );
update_post_meta( $post_id, '_parcel_machine_desc', $parcel_machine_desc );
$parcels = $_POST['parcel'];
$cod_amounts = $_POST['cod_amount'];
$easypack_pacels = array();
foreach ( $parcels as $key => $parcel )
{
$easypack_pacels[] = array( 'package_size' => $parcel, 'cod_amount' => $cod_amounts[$key] );
}
update_post_meta( $post_id, '_easypack_parcels', $easypack_pacels );
$easypack_send_method = $_POST['easypack_send_method'];
update_post_meta( $post_id, '_easypack_send_method', $easypack_send_method );
}
}
public function add_meta_boxes( $post_type, $post ) {
if ( $post->post_type == 'shop_order' )
{
$order = wc_get_order( $post->ID );
if ( $order->has_shipping_method($this->id) ) {
add_meta_box( 'easypack_parcel_machines', __('InPost', EasyPack::$text_domain ) . $this->get_logo(), array( $this, 'order_metabox' ), 'shop_order', 'side', 'default' );
}
}
}
public function order_metabox( $post ) {
self::order_metabox_content( $post );
}
public static function order_metabox_content( $post, $output = true ) {
if ( ! $output ) ob_start();
$order_id = $post->ID;
$order = wc_get_order( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
$parcel_machines = EasyPack_API()->machines_cod_options();
$parcel_machine_id = get_post_meta( $post->ID, '_parcel_machine_id', true );
$parcels = get_post_meta( $post->ID, '_easypack_parcels', true );
$package_sizes = EasyPack()->get_package_sizes();
$package_sizes_display = EasyPack()->get_package_sizes_display();
if ( $parcels == '' ) {
$parcels = array();
$parcel = array( 'package_size' => get_option( 'easypack_default_package_size', 'A' ), 'cod_amount' => $order->get_total() );
$parcels[] = $parcel;
}
$send_methods = array( 'parcel_machine' => __( 'Parcel locker', EasyPack::$text_domain ), 'courier' => __( 'Courier', EasyPack::$text_domain ) );
$send_method = get_post_meta( $post->ID, '_easypack_send_method', true );
if ( $send_method == '' ) {
$send_method = get_option( 'easypack_default_send_method', 'parcel_machine' );
}
$stickers_url = site_url('?easypack_download=1&easypack_parcel_machines_stickers=1&order_id=' . $order_id . '&security=' . wp_create_nonce( 'easypack_nonce' ) );
$tracking_url = false;
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url();
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['easypack_data']['id'] . ',';
}
$tracking_url = trim( $tracking_url, ',' );
}
$disabled = false;
if ( $status != 'new' ) $disabled = true;
$send_method_disabled = false;
if ( EasyPack_API()->api_country() == 'PL' || EasyPack_API()->api_country() == 'GB' ) {
$send_methods = array( 'parcel_machine' => __( 'Parcel locker', EasyPack::$text_domain ), 'courier' => __( 'Courier', EasyPack::$text_domain ) );
}
else {
$send_methods = array( 'courier' => __( 'Courier', EasyPack::$text_domain ) );
}
include( 'views/html-order-matabox-parcel-machines_cod.php' );
wp_nonce_field( 'easypack_box_data_parcel_machines_cod', 'easypack_box_data_parcel_machines_cod' );
if ( ! $output )
{
$out = ob_get_clean();
return $out;
}
}
public function woocommerce_review_order_after_shipping() {
if ( in_array( $this->id, WC()->session->get('chosen_shipping_methods') ) ) {
$parcel_machines = EasyPack_API()->machines_cod_options();
$args = array( 'parcel_machines' => $parcel_machines );
$args['parcel_machine_id'] = WC()->session->get( 'parcel_machine_id' );
wc_get_template( 'checkout/easypack-review-order-after-shipping.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
}
/**
* @param unknown $package
*
*/
public function calculate_shipping_table_rate( $package ) {
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
foreach ( $rates as $key => $rate) {
if ( empty($rates[$key]['min']) || trim( $rates[$key]['min'] ) == '' ) {
$rates[$key]['min'] = 0;
}
if ( empty($rates[$key]['max']) || trim( $rates[$key]['max'] ) == '' ) {
$rates[$key]['max'] = PHP_INT_MAX;
}
}
$value = 0;
if ( $this->based_on == 'price' ) {
$value = $this->package_subtotal( $package['contents'] );
}
if ( $this->based_on == 'weight' ) {
$value = $this->package_weight( $package['contents'] );
}
foreach ( $rates as $rate ) {
if ( floatval($rate['min']) <= $value && floatval($rate['max']) >= $value )
{
$cost = 0;
if ( isset( $rate['percent'] ) && floatval( $rate['percent']) != 0 ) {
$cost = $package['contents_cost'] * ( floatval( $rate['percent'] ) / 100);
}
$cost = $cost + floatval( $rate['cost'] );
$add_rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $cost,
);
$this->add_rate( $add_rate );
return;
}
}
}
public static function ajax_create_package( $courier = false ) {
$ret = array( 'status' => 'ok' );
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$parcels = $_POST['parcels'];
$cod_amounts = $_POST['cod_amounts'];
$parcel_machine_id = $_POST['parcel_machine_id'];
$send_method = $_POST['send_method'];
$order_parcels = array();
$total_amount = 0;
foreach ( $cod_amounts as $amount ) {
$total_amount = $total_amount+floatval($amount);
}
if ( $total_amount != $order->get_total() ) {
$ret['status'] = 'error';
$ret['message'] = sprintf( __( 'Order total %s do not equals total COD amounts %s.' ), $order->get_total(), $total_amount );
}
else {
foreach ( $parcels as $key => $parcel )
{
$args = array();
$args['target_machine_id'] = $parcel_machine_id;
$args['size'] = $parcel;
$args['receiver_email'] = $order->billing_email;
$args['receiver_phone'] = $order->billing_phone;
if ( $send_method == 'parcel_machine' )
$args['source_machine_id'] = get_option( 'easypack_default_machine_id' );
$args['customer_reference'] = sprintf( __( 'Order %s', EasyPack::$text_domain ), $order->get_order_number() );
$args['cod_amount'] = $cod_amounts[$key];
$args['additional1'] = __( 'Order ', EasyPack::$text_domain ) . $order->get_order_number();
try {
$easypack_data = EasyPack_API()->customer_parcel_create($args);
$order_parcels[] = array( 'package_size' => $parcel, 'easypack_data' => $easypack_data );
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] = __( 'There are some errors. Please fix it:' ) . $e->getMessage();
break;
}
}
if ( $ret['status'] == 'ok' ) {
update_post_meta( $order_id, '_easypack_parcels', $order_parcels );
update_post_meta( $order_id, '_easypack_status', 'created' );
update_post_meta( $order_id, '_easypack_send_method', $send_method );
$order->add_order_note( __( 'Shipment created', EasyPack::$text_domain ), false);
$ret['content'] = self::order_metabox_content( $post, false );
}
}
echo json_encode( $ret );
wp_die();
}
public static function ajax_cancel_package() {
$ret = array( 'status' => 'ok', 'message' => '' );
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
try {
$cancelled_parcel = EasyPack_API()->customer_parcel_cancel( $parcel['easypack_data']['id'] );
if ( $cancelled_parcel['status'] != 'cancelled') {
throw new Exception( sprintf( __('Cannot cancel package %s'), $parcel['easypack_data']['id'] ) );
}
unset( $easypack_parcels[$key]['easypack_data'] );
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] .= $e->getMessage();
}
}
}
if ( $ret['status'] == 'ok' ) {
update_post_meta( $order_id, '_easypack_parcels', $order_parcels );
update_post_meta( $order_id, '_easypack_status', 'new' );
$order->add_order_note( __( 'Shipment canceled', EasyPack::$text_domain ), false);
$ret['content'] = self::order_metabox_content( $post, false );
}
echo json_encode( $ret );
wp_die();
}
public static function ajax_get_payment_status() {
$ret = array( 'status' => 'ok', 'message' => '' );
$paecel_id = $_POST['parcel_id'];
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
$stickers = array();
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
try {
if ( $parcel['easypack_data']['id'] == $parcel_id ) {
$easypack_parcel = EasyPack_API()->customer_parcel( $parcel_id );
}
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] .= $e->getMessage();
}
}
}
if ( $ret['status'] == 'ok' ) {
}
echo json_encode( $ret );
wp_die();
}
}
}

View File

@@ -0,0 +1,724 @@
<?php
/**
* EasyPack Shipping Method Parcel Machines
*
* @author WPDesk
* @category Admin
* @package EasyPack/Admin
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
if ( ! class_exists( 'EasyPack_Shippng_Parcel_Machines' ) ) {
class EasyPack_Shippng_Parcel_Machines extends WC_Shipping_Method {
/**
* Constructor for shipping class
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'easypack_parcel_machines';
$this->method_title = __( 'InPost Locker 24/7', EasyPack::$text_domain );
$this->init();
}
/**
* Init your settings
*
*
* @access public
* @return void
*/
function init() {
$this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
$this->init_settings(); // This is part of the settings API. Loads settings you previously init.
// Define user set variables
$this->title = $this->get_option( 'title' );
$this->free_shipping_cost = $this->get_option( 'free_shipping_cost' );
$this->flat_rate = $this->get_option( 'flat_rate' );
$this->cost_per_order = $this->get_option( 'cost_per_order' );
$this->based_on = $this->get_option( 'based_on' );
$this->tax_status = get_option( 'easypack_tax_status' );
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
add_action( 'woocommerce_review_order_after_shipping', array( $this, 'woocommerce_review_order_after_shipping') );
add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'woocommerce_checkout_update_order_meta') );
add_action( 'woocommerce_checkout_process', array($this, 'woocommerce_checkout_process' ) );
add_action( 'save_post', array( $this, 'save_post' ) );
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ), 10, 2 );
add_filter( 'woocommerce_cart_shipping_method_full_label', array( $this, 'woocommerce_cart_shipping_method_full_label' ), 10, 2 );
add_filter( 'woocommerce_order_shipping_to_display_shipped_via', array( $this, 'woocommerce_order_shipping_to_display_shipped_via' ), 10, 2 );
add_filter( 'woocommerce_my_account_my_orders_actions', array( $this, 'woocommerce_my_account_my_orders_actions' ), 10, 2 );
add_action( 'woocommerce_email_after_order_table', array( $this, 'woocommerce_email_after_order_table' ), 10, 3 );
}
public function admin_options()
{
?>
<table class="form-table">
<?php $this->generate_settings_html(); ?>
</table>
<script type="text/javascript">
function display_rates() {
if ( jQuery('.easypack_flat_rate').prop('checked') ) {
jQuery('.easypack_cost_per_order').closest('tr').css('display','table-row');
jQuery('.easypack_based_on').closest('tr').css('display','none');
jQuery('.easypack_rates').closest('tr').css('display','none');
jQuery('#woocommerce_easypack_parcel_machines_1').css('display','none');
jQuery('#woocommerce_easypack_parcel_machines_cod_1').css('display','none');
}
else {
jQuery('.easypack_cost_per_order').closest('tr').css('display','none');
jQuery('.easypack_based_on').closest('tr').css('display','table-row');
jQuery('.easypack_rates').closest('tr').css('display','table-row');
jQuery('#woocommerce_easypack_parcel_machines_1').css('display','block');
jQuery('#woocommerce_easypack_parcel_machines_cod_1').css('display','block');
}
}
jQuery('.easypack_flat_rate').change(function() {
display_rates();
});
display_rates();
</script>
<?php
}
public function generate_rates_html( $key, $data )
{
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
ob_start();
include( 'views/html-rates.php' );
return ob_get_clean();
}
public function init_form_fields() {
$settings = array(
array(
'title' => __( 'General settings', EasyPack::$text_domain ),
'type' => 'title',
'description' => '',
'id' => 'section_general_settings',
),
'enabled' => array(
'title' => __( 'Enable/disable', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Enable this shipping metod', EasyPack::$text_domain ),
'default' => 'no',
),
'title' => array(
'title' => __( 'Method title', EasyPack::$text_domain ),
'type' => 'text',
'default' => __( 'InPost Locker 24/7', EasyPack::$text_domain ),
'desc_tip' => false
),
'free_shipping_cost' => array(
'title' => __( 'Free shipping', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
'default' => '',
'desc_tip' => __( 'Enter the amount of the order from which the shipping will be free (does not include virtual products). ', EasyPack::$text_domain ),
'placeholder' => '0.00'
),
'flat_rate' => array(
'title' => __( 'Flat rate', EasyPack::$text_domain ),
'type' => 'checkbox',
'label' => __( 'Set a flat-rate shipping fee for the entire order.', EasyPack::$text_domain ),
'class' => 'easypack_flat_rate',
'default' => 'yes',
),
'cost_per_order' => array(
'title' => __( 'Cost per order', EasyPack::$text_domain ),
'type' => 'number',
'custom_attributes' => array(
'step' => 'any',
'min' => '0'
),
'class' => 'easypack_cost_per_order',
'default' => '',
'desc_tip' => 'Set a flat-rate shipping for all orders.',
'placeholder' => '0.00'
),
array(
'title' => __( 'Rates table', EasyPack::$text_domain ),
'type' => 'title',
'description' => '',
'id' => 'section_general_settings',
),
'based_on' => array(
'title' => __( 'Based on', EasyPack::$text_domain ),
'type' => 'select',
'desc_tip' => __( 'Select the method of calculating shipping cost. If the cost of shipping is to be calculated based on the weight of the cart and the products do not have a defined weight, the cost will be calculated incorrectly.', EasyPack::$text_domain ),
'class' => 'wc-enhanced-select easypack_based_on',
'options' => array(
'price' => __( 'Price', EasyPack::$text_domain ),
'weight' => __( 'Weight', EasyPack::$text_domain )
)
),
'rates' => array(
'title' => '',
'type' => 'rates',
'class' => 'easypack_rates',
'default' => '',
'desc_tip' => '',
),
);
$this->form_fields = $settings;
}
public function process_admin_options()
{
parent::process_admin_options();
$rates = $_POST['rates'];
update_option('woocommerce_' . $this->id . '_rates', $rates );
}
public function calculate_shipping_free_shipping( $package ) {
if ( !empty($this->free_shipping_cost) && $this->free_shipping_cost <= $package['contents_cost'] )
{
$add_rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => 0,
);
$this->add_rate( $add_rate );
return true;
}
return false;
}
public function calculate_shipping_flat( $package ) {
if ( $this->flat_rate == 'yes' )
{
$add_rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $this->cost_per_order,
);
$this->add_rate( $add_rate );
return true;
}
return false;
}
public function package_weight( $items ) {
$weight = 0;
foreach( $items as $item )
$weight += $item['data']->weight * $item['quantity'];
return $weight;
}
public function package_subtotal( $items ) {
$subtotal = 0;
foreach( $items as $item )
$subtotal += $item['line_subtotal'] + $item['line_subtotal_tax'];
return $subtotal;
}
/**
* @param unknown $package
*
*/
public function calculate_shipping_table_rate( $package ) {
$rates = get_option('woocommerce_' . $this->id . '_rates', array() );
foreach ( $rates as $key => $rate) {
if ( empty($rates[$key]['min']) || trim( $rates[$key]['min'] ) == '' ) {
$rates[$key]['min'] = 0;
}
if ( empty($rates[$key]['max']) || trim( $rates[$key]['max'] ) == '' ) {
$rates[$key]['max'] = PHP_INT_MAX;
}
}
$value = 0;
if ( $this->based_on == 'price' ) {
$value = $this->package_subtotal( $package['contents'] );
}
if ( $this->based_on == 'weight' ) {
$value = $this->package_weight( $package['contents'] );
}
foreach ( $rates as $rate ) {
if ( floatval($rate['min']) <= $value && floatval($rate['max']) >= $value )
{
$add_rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => $rate['cost'],
);
$this->add_rate( $add_rate );
return;
}
}
}
public function calculate_shipping( $package = array() ) {
if ( strtoupper( $package['destination']['country'] ) == strtoupper( str_replace( 'test-', '', get_option( 'easypack_api_country', 'pl' ) ) ) ) {
if ( ! $this->calculate_shipping_free_shipping( $package ) )
{
if ( ! $this->calculate_shipping_flat( $package ) )
{
$this->calculate_shipping_table_rate( $package );
}
}
}
}
public function woocommerce_review_order_after_shipping() {
if ( in_array( $this->id, WC()->session->get('chosen_shipping_methods') ) ) {
$parcel_machines = EasyPack_API()->machines_options();
$args = array( 'parcel_machines' => $parcel_machines );
$args['parcel_machine_id'] = WC()->session->get( 'parcel_machine_id' );
wc_get_template( 'checkout/easypack-review-order-after-shipping.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
}
public function woocommerce_checkout_process() {
if ( in_array( $this->id, WC()->session->get('chosen_shipping_methods') ) ) {
if ( empty( $_POST['parcel_machine_id'] ) ) {
wc_add_notice( __( 'Parcel locker must be choosen.', EasyPack::$text_domain ), 'error' );
}
else {
WC()->session->set( 'parcel_machine_id', $_POST['parcel_machine_id'] );
}
$billing_phone = $_POST['billing_phone'];
if ('gb' !== get_option('easypack_api_country')) {
$validate_phone = EasyPack_API()->validate_phone( $billing_phone );
if ( $validate_phone !== true ) {
wc_add_notice( $validate_phone, 'error' );
}
}
}
}
public function woocommerce_checkout_update_order_meta( $order_id ) {
if ($_POST['parcel_machine_id']) {
update_post_meta($order_id, '_parcel_machine_id', esc_attr($_POST['parcel_machine_id']));
}
if ($_POST['parcel_machine_desc']) {
update_post_meta($order_id, '_parcel_machine_desc', esc_attr($_POST['parcel_machine_desc']));
}
}
public function save_post( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['easypack_box_data_parcel_machines'] ) ) {
return;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['easypack_box_data_parcel_machines'], 'easypack_box_data_parcel_machines' ) ) {
return;
}
// If this is an autosave, our form has not been submitted, so we don't want to do anything.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
$status = get_post_meta( $post_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
if ( $status == 'new' ) {
$parcel_machine_id = $_POST['parcel_machine_id'];
$parcel_machine_desc = $_POST['parcel_machine_desc'];
update_post_meta( $post_id, '_parcel_machine_id', $parcel_machine_id );
update_post_meta( $post_id, '_parcel_machine_desc', $parcel_machine_desc );
$parcels = $_POST['parcel'];
$easypack_pacels = array();
foreach ( $parcels as $parcel )
{
$easypack_pacels[] = array( 'package_size' => $parcel );
}
update_post_meta( $post_id, '_easypack_parcels', $easypack_pacels );
$easypack_send_method = $_POST['send_method'];
update_post_meta( $post_id, '_easypack_send_method', $easypack_send_method );
}
}
public function get_logo() {
return '<img style="height:22px; float:right;" src="' . untrailingslashit( EasyPack()->getPluginUrl() ). '/assets/images/logo/small/white.png"/>';
}
public function add_meta_boxes( $post_type, $post ) {
if ( $post->post_type == 'shop_order' )
{
$order = wc_get_order( $post->ID );
if ( $order->has_shipping_method($this->id) ) {
add_meta_box( 'easypack_parcel_machines'
, __('InPost', EasyPack::$text_domain ) . $this->get_logo()
, array( $this, 'order_metabox' )
, 'shop_order'
, 'side'
, 'default'
);
}
}
}
public function order_metabox( $post ) {
self::order_metabox_content( $post );
}
public static function order_metabox_content( $post, $output = true ) {
if ( ! $output ) ob_start();
$order_id = $post->ID;
$order = wc_get_order( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
if ( $status == '' ) $status = 'new';
$parcel_machines = EasyPack_API()->machines_options();
$parcel_machine_id = get_post_meta( $post->ID, '_parcel_machine_id', true );
$parcels = get_post_meta( $post->ID, '_easypack_parcels', true );
$package_sizes = EasyPack()->get_package_sizes();
$package_sizes_display = EasyPack()->get_package_sizes_display();
if ( $parcels == '' ) {
$parcels = array();
$parcel = array( 'package_size' => get_option( 'easypack_default_package_size', 'A' ) );
$parcels[] = $parcel;
}
$send_methods = array( 'parcel_machine' => __( 'Parcel locker', EasyPack::$text_domain ), 'courier' => __( 'Courier', EasyPack::$text_domain ) );
$send_method = get_post_meta( $post->ID, '_easypack_send_method', true );
if ( $send_method == '' ) {
$send_method = get_option( 'easypack_default_send_method', 'parcel_machine' );
}
$stickers_url = site_url('?easypack_download=1&easypack_parcel_machines_stickers=1&order_id=' . $order_id . '&security=' . wp_create_nonce( 'easypack_nonce' ) );
$tracking_url = false;
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url();
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['easypack_data']['id'] . ',';
}
$tracking_url = trim( $tracking_url, ',' );
}
$disabled = false;
if ( $status != 'new' ) $disabled = true;
$send_method_disabled = false;
if ( EasyPack_API()->api_country() == 'PL') {
$send_methods = array( 'parcel_machine' => __( 'Parcel locker', EasyPack::$text_domain ), 'courier' => __( 'Courier', EasyPack::$text_domain ) );
}
else {
$send_methods = array( 'courier' => __( 'Courier', EasyPack::$text_domain ) );
}
include( 'views/html-order-matabox-parcel-machines.php' );
wp_nonce_field( 'easypack_box_data_parcel_machines', 'easypack_box_data_parcel_machines' );
if ( ! $output )
{
$out = ob_get_clean();
return $out;
}
}
public static function ajax_create_package( $courier = false ) {
$ret = array( 'status' => 'ok' );
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$parcels = $_POST['parcels'];
$parcel_machine_id = $_POST['parcel_machine_id'];
$send_method = $_POST['send_method'];
$order_parcels = array();
foreach ( $parcels as $parcel )
{
$args = array();
$args['target_machine_id'] = $parcel_machine_id;
$args['size'] = $parcel;
$args['receiver_email'] = $order->billing_email;
$args['receiver_phone'] = $order->billing_phone;
if ( $send_method == 'parcel_machine' )
$args['source_machine_id'] = get_option( 'easypack_default_machine_id' );
$args['customer_reference'] = sprintf( __( 'Order %s', EasyPack::$text_domain ), $order->get_order_number() );
if ( EasyPack_API()->api_country() == 'FR') {
$args['receiver_phone'] = ltrim( $args['receiver_phone'], "0" );
$args['receiver'] = array();
$args['receiver']['first_name'] = $order->shipping_first_name;
$args['receiver']['last_name'] = $order->shipping_last_name;
$args['receiver']['address'] = array();
$args['receiver']['address']['street'] = $order->shipping_address_1;
$args['receiver']['address']['building_no'] = $order->shipping_address_2;
$args['receiver']['address']['post_code'] = $order->shipping_postcode;
$args['receiver']['address']['city'] = $order->shipping_city;
if ( $order->shipping_company && trim( $order->shipping_company ) != '' ) {
$args['receiver']['company_name'] = $order->shipping_company;
}
}
if ( EasyPack_API()->api_country() == 'IT') {
$args['receiver'] = array();
$args['receiver']['first_name'] = $order->shipping_first_name;
$args['receiver']['last_name'] = $order->shipping_last_name;
}
if ( EasyPack_API()->api_country() == 'FR' || EasyPack_API()->api_country() == 'IT' ) {
$args['sender_address'] = array();
$args['sender_address']['first_name'] = get_option('easypack_sender_first_name');
$args['sender_address']['last_name'] = get_option('easypack_sender_last_name');
$args['sender_address']['company_name'] = get_option('easypack_sender_company_name');
$args['sender_address']['street'] = get_option('easypack_sender_street');
$args['sender_address']['building_no'] = get_option('easypack_sender_building_no');
$args['sender_address']['flat_no'] = get_option('easypack_sender_flat_no');
$args['sender_address']['post_code'] = get_option('easypack_sender_post_code');
$args['sender_address']['city'] = get_option('easypack_sender_city');
}
try {
//update_post_meta( $order_id, '_easypack_parcel_create_args', $args );
$easypack_data = EasyPack_API()->customer_parcel_create($args);
$order_parcels[] = array( 'package_size' => $parcel, 'easypack_data' => $easypack_data );
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] = __( 'There are some errors. Please fix it:' ) . $e->getMessage();
break;
}
}
if ( $ret['status'] == 'ok' ) {
update_post_meta( $order_id, '_easypack_parcels', $order_parcels );
update_post_meta( $order_id, '_easypack_status', 'created' );
update_post_meta( $order_id, '_easypack_send_method', $send_method );
$order->add_order_note( __( 'Shipment created', EasyPack::$text_domain ), false);
$ret['content'] = self::order_metabox_content( $post, false );
}
echo json_encode( $ret );
wp_die();
}
public static function ajax_cancel_package() {
$ret = array( 'status' => 'ok', 'message' => '' );
$order_id = $_POST['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
try {
$cancelled_parcel = EasyPack_API()->customer_parcel_cancel( $parcel['easypack_data']['id'] );
if ( $cancelled_parcel['status'] != 'cancelled') {
throw new Exception( sprintf( __('Cannot cancel package %s'), $parcel['easypack_data']['id'] ) );
}
unset( $easypack_parcels[$key]['easypack_data'] );
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] .= $e->getMessage();
}
}
}
if ( $ret['status'] == 'ok' ) {
update_post_meta( $order_id, '_easypack_parcels', [] );
update_post_meta( $order_id, '_easypack_status', 'new' );
$order->add_order_note( __( 'Shipment canceled', EasyPack::$text_domain ), false);
$ret['content'] = self::order_metabox_content( $post, false );
}
echo json_encode( $ret );
wp_die();
}
public static function ajax_dispatch_order() {
$ret = array( 'status' => 'ok', 'message' => '' );
$parcels = $_POST['parcels'];
$ret['parcels'] = $parcels;
$dispatch_point = $_POST['dispatch_point'];
$ret['dispatch_point'] = $dispatch_point;
$parcel_ids = array();
foreach ( $parcels as $parcel ) {
$parcel_exploded = explode( '.', $parcel );
$parcel_ids[] = $parcel_exploded[2];
}
$args = array( 'parcel_ids' => $parcel_ids );
try {
$response = EasyPack_API()->dispatch_order( $dispatch_point, $args );
$ret['id'] = $response['id'];
}
catch ( Exception $e ) {
$ret['status'] = 'error';
$ret['message'] .= $e->getMessage();
}
echo json_encode( $ret );
wp_die();
}
public static function get_stickers() {
$nonce = $_GET['security'];
if ( ! wp_verify_nonce( $nonce, 'easypack_nonce' ) ) {
echo __( 'Security check - bad nonce!', EasyPack::$text_domain );
return;
}
$order_id = $_GET['order_id'];
$order = wc_get_order($order_id);
$post = get_post( $order_id );
$status = get_post_meta( $order_id, '_easypack_status', true );
$easypack_parcels = get_post_meta( $order_id, '_easypack_parcels', true );
$stickers = array();
if ( $easypack_parcels ) {
foreach ( $easypack_parcels as $key => $parcel ) {
try {
$easypack_data = EasyPack_API()->customer_parcel( $parcel['easypack_data']['id'] );
if ( $parcel['easypack_data']['status'] != $easypack_data['status'] ) {
$parcel['easypack_data'] = $easypack_data;
$easypack_parcels[$key] = $parcel;
update_post_meta( $order_id, '_easypack_parcels', $easypack_parcels );
}
if ( $parcel['easypack_data']['status'] == 'created' ) {
$easypack_data = EasyPack_API()->customer_parcel_pay( $parcel['easypack_data']['id'] );
$easypack_parcels[$key]['easypack_data'] = $easypack_data;
update_post_meta( $order_id, '_easypack_parcels', $easypack_parcels );
}
$stickers[] = EasyPack_API()->customer_parcel_sticker( $parcel['easypack_data']['id'] );
}
catch ( Exception $e ) {
echo $e->getMessage();
return;
}
}
}
$file = EasyPack_Helper()->write_stickers_to_file( $stickers );
if ( $status == 'created' ) {
update_post_meta( $order_id, '_easypack_status', 'prepared' );
}
EasyPack_Helper()->get_file($file, __( 'stickers', EasyPack::$text_domain ) . '_' . $order->get_id() . '.pdf', 'application/pdf' );
}
function woocommerce_cart_shipping_method_full_label( $label, $method ) {
if ( $method->id == $this->id ) {
$img = ' <span class="easypack-shipping-method-logo"><img style="" src="' . EasyPack()->getPluginUrl(). '/assets/images/logo/small/white.png" /><span>';
$label .= $img;
}
return $label;
}
function woocommerce_order_shipping_to_display_shipped_via( $via, $order ) {
if ( $order->has_shipping_method( $this->id ) ) {
$img = ' <span class="easypack-shipping-method-logo" style="display: inline;"><img style="max-width: 100; max-height: 40px; display: inline; border:none;" src="' . EasyPack()->getPluginUrl(). '/assets/images/logo/small/white.png" /><span>';
$via .= $img;
}
return $via;
}
function woocommerce_my_account_my_orders_actions( $actions, $order ) {
if ( $order->has_shipping_method($this->id) ) {
$status = get_post_meta( $order->id, '_easypack_status', true );
$tracking_url = false;
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url();
$parcels = get_post_meta( $order->id, '_easypack_parcels', true );
if ( $parcels != '' ) {
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['easypack_data']['id'] . ',';
}
}
$tracking_url = trim( $tracking_url, ',' );
}
if ( $tracking_url ) {
$actions['easypack_tracking'] = array(
'url' => $tracking_url,
'name' => __( 'Track shipment', EasyPack::$text_domain )
);
}
}
return $actions;
}
function woocommerce_email_after_order_table( $order, $is_admin, $plain_text ) {
if ( $order->has_shipping_method($this->id) ) {
$status = get_post_meta( $order->id, '_easypack_status', true );
if ( $status != '' && $status != 'new' ) {
$tracking_url = false;
$package_numbers = '';
if ( $status != 'new' ) {
$tracking_url = EasyPack_Helper()->get_tracking_url();
$parcels = get_post_meta( $order->id, '_easypack_parcels', true );
foreach ( $parcels as $parcel ) {
$tracking_url .= $parcel['easypack_data']['id'] . ',';
$package_numbers = $parcel['easypack_data']['id'] . ', ';
}
$package_numbers = trim( trim ( $package_numbers ) , ',' );
$tracking_url = trim( $tracking_url, ',' );
}
if ( $tracking_url ) {
$args['tracking_url'] = $tracking_url;
$args['package_numbers'] = $package_numbers;
$args['logo'] = untrailingslashit( EasyPack()->getPluginUrl() ). '/assets/images/logo/small/white.png';
if ( $plain_text ) {
wc_get_template( 'emails/plain/after-order-table.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
else {
wc_get_template( 'emails/after-order-table.php', $args, '', plugin_dir_path( EasyPack()->getPluginFilePath() ) . 'templates/' );
}
}
}
}
}
}
}

View File

@@ -0,0 +1,214 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
?>
<?php foreach ( $parcels as $key => $parcel ) : ?>
<div>
<?php if ( $status == 'new' ) : ?>
<?php
$params = array(
'type' => 'select',
'options' => $package_weights,
'class' => array('easypack_parcel'),
'input_class' => array('easypack_parcel_weight'),
'label' => __( 'Parcel', EasyPack::$text_domain ) . ' ',
);
woocommerce_form_field('parcel[' . $key . '][weight]', $params, $parcel['package_weight'] );
_e( 'Dimensions (max 60x40x40)', EasyPack::$text_domain );
?>
<div>
<?php
$params = array(
'type' => 'number',
'class' => 'easypack_parcel_width',
'input_class' => 'easypack_parcel_width',
'label' => __( 'Width', EasyPack::$text_domain ) . ' ',
'custom_attributes' => array( 'min' => '1', 'max' => '60' ),
'style' => 'max-width: 70px;',
'id' => 'parcel[' . $key . '][width]',
'value' => $parcel['package_width'],
'description' => 'cm'
);
woocommerce_wp_text_input( $params )
?>
<?php
$params = array(
'type' => 'number',
'class' => 'easypack_parcel_height',
'input_class' => 'easypack_parcel_height',
'label' => __( 'Height', EasyPack::$text_domain ) . ' ',
'custom_attributes' => array( 'min' => '1', 'max' => '40' ),
'style' => 'max-width: 70px;',
'id' => 'parcel[' . $key . '][height]',
'value' => $parcel['package_height'],
'description' => 'cm'
);
woocommerce_wp_text_input( $params )
?>
<?php
$params = array(
'type' => 'number',
'class' => 'easypack_parcel_length',
'input_class' => 'easypack_parcel_length',
'label' => __( 'Length', EasyPack::$text_domain ) . ' ',
'custom_attributes' => array( 'min' => '1', 'max' => '40' ),
'style' => 'max-width: 70px;',
'id' => 'parcel[' . $key . '][length]',
'value' => $parcel['package_length'],
'description' => 'cm'
);
woocommerce_wp_text_input( $params )
?>
</div>
<?php
?>
<?php else : ?>
<?php if ( $status == "Processing" ) : ?>
<?php _e( 'Processing', EasyPack::$text_domain ); ?>
<?php else : ?>
<?php _e( 'Weight', EasyPack::$text_domain ); ?> <?php echo $parcel['package_weight']; ?> <?php _e( 'kg', EasyPack::$text_domain ); ?>
, <?php _e( 'dimensions', EasyPack::$text_domain ); ?> <?php echo $parcel['package_width']; ?>x<?php echo $parcel['package_height']; ?>x<?php echo $parcel['package_length']; ?>
<?php _e( 'cm', EasyPack::$text_domain ); ?>:
<?php echo $parcel['crossborder_data']['tracking_number']; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
$params = array(
'type' => 'select',
'options' => $send_methods,
'class' => array('wc-enhanced-select'),
'custom_attributes' => $custom_attributes,
'label' => __('Send method', EasyPack::$text_domain ),
);
woocommerce_form_field('easypack_send_method', $params, $send_method );
?>
<p>
<?php if ( $status == 'new' ) : ?>
<button id="easypack_send_parcels" class="button button-primary"><?php _e('Send parcel', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php if ( $status == 'created' ) : ?>
<button id="easypack_cancel_parcels" class="button"><?php _e('Cancel parcels', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php if ( $status == 'ReadyToBeSent' || $status == 'prepared' ) : ?>
<a href="<?php echo $stickers_url; ?>" id="easypack_get_stickers" class="button button-primary" target="_blank"><?php _e('Get sticker(s)', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<?php if ( $tracking_url ) : ?>
<a href="<?php echo $tracking_url; ?>" class="button" target="_blank"><?php _e('Track shipment', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<?php if ( $status == 'Processing' ) : ?>
<?php _e( 'Processing', EasyPack::$text_domain ); ?>
<?php endif; ?>
<span id="easypack_spinner" class="spinner"></span>
</p>
<p id="easypack_error"></p>
<a href="#" download id="easypack_download" hidden></a>
<script type="text/javascript">
if ( jQuery().select2 ) {
jQuery("#parcel_machine_id").select2();
}
jQuery('#easypack_send_parcels').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var parcels = [];
jQuery('select.easypack_parcel_weight').each(function(i) {
var parent_div = jQuery(this).parent().parent();
parcels[i] = {
'weight' : jQuery(this).val(),
'width' : jQuery(parent_div).find('.easypack_parcel_width').val(),
'height' : jQuery(parent_div).find('.easypack_parcel_height').val(),
'length' : jQuery(parent_div).find('.easypack_parcel_length').val(),
};
})
var data = {
action: 'easypack',
easypack_action: 'crossborder_courier_create_package',
security: easypack_nonce,
order_id: <?php echo $order_id; ?>,
parcels: parcels,
send_method: jQuery('#easypack_send_method').val(),
};
console.log(data);
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_send_parcels').attr('disabled',false);
});
return false;
});
function crossborder_processing() {
console.log(jQuery('#easypack_status').val());
if ( jQuery('#easypack_status').val() == 'Processing' ) {
jQuery("#easypack_spinner").addClass("is-active");
var data = {
action: 'easypack',
easypack_action: 'crossborder_courier_processing',
security: easypack_nonce,
order_id: <?php echo $order_id; ?>,
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
jQuery("#easypack_parcel_machines .inside").html(response.content);
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_cancel_parcels').attr('disabled',false);
});
}
}
crossborder_processing();
</script>

View File

@@ -0,0 +1,224 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
$params = array(
'type' => 'select',
'options' => $parcel_machines,
'class' => array('wc-enhanced-select'),
'custom_attributes' => $custom_attributes,
'label' => __('Selected parcel locker', EasyPack::$text_domain ),
);
woocommerce_form_field('parcel_machine_id', $params, $parcel_machine_id );
?>
<?php foreach ( $parcels as $key => $parcel ) : ?>
<div>
<?php if ( $status == 'new' ) : ?>
<?php
$params = array(
'type' => 'select',
'options' => $package_weights,
'class' => array('easypack_parcel_weight'),
'input_class' => array('easypack_parcel_weight'),
'label' => __( 'Parcel', EasyPack::$text_domain ) . ' ',
);
woocommerce_form_field('parcel[' . $key . '][weight]', $params, $parcel['package_weight'] );
_e( 'Dimensions (max 64x41x38)', EasyPack::$text_domain );
?>
<div>
<?php
$params = array(
'type' => 'number',
'class' => 'easypack_parcel_width',
'input_class' => 'easypack_parcel_width',
'label' => __( 'Width', EasyPack::$text_domain ) . ' ',
'custom_attributes' => array( 'min' => '1', 'max' => '64' ),
'style' => 'max-width: 70px;',
'id' => 'parcel[' . $key . '][width]',
'value' => $parcel['package_width'],
'description' => 'cm'
);
woocommerce_wp_text_input( $params )
?>
<?php
$params = array(
'type' => 'number',
'class' => 'easypack_parcel_height',
'input_class' => 'easypack_parcel_height',
'label' => __( 'Height', EasyPack::$text_domain ) . ' ',
'custom_attributes' => array( 'min' => '1', 'max' => '41' ),
'style' => 'max-width: 70px;',
'id' => 'parcel[' . $key . '][height]',
'value' => $parcel['package_height'],
'description' => 'cm'
);
woocommerce_wp_text_input( $params )
?>
<?php
$params = array(
'type' => 'number',
'class' => 'easypack_parcel_length',
'input_class' => 'easypack_parcel_length',
'label' => __( 'Length', EasyPack::$text_domain ) . ' ',
'custom_attributes' => array( 'min' => '1', 'max' => '38' ),
'style' => 'max-width: 70px;',
'id' => 'parcel[' . $key . '][length]',
'value' => $parcel['package_length'],
'description' => 'cm'
);
woocommerce_wp_text_input( $params )
?>
</div>
<?php
?>
<?php else : ?>
<?php if ( $status == "Processing" ) : ?>
<?php _e( 'Processing', EasyPack::$text_domain ); ?>
<?php else : ?>
<?php _e( 'Weight', EasyPack::$text_domain ); ?> <?php echo $parcel['package_weight']; ?> <?php _e( 'kg', EasyPack::$text_domain ); ?>
, <?php _e( 'dimensions', EasyPack::$text_domain ); ?> <?php echo $parcel['package_width']; ?>x<?php echo $parcel['package_height']; ?>x<?php echo $parcel['package_length']; ?>
<?php _e( 'cm', EasyPack::$text_domain ); ?>:
<?php echo $parcel['crossborder_data']['tracking_number']; ?>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endforeach; ?>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
$params = array(
'type' => 'select',
'options' => $send_methods,
'class' => array('wc-enhanced-select'),
'custom_attributes' => $custom_attributes,
'label' => __('Send method', EasyPack::$text_domain ),
);
woocommerce_form_field('easypack_send_method', $params, $send_method );
?>
<p>
<?php if ( $status == 'new' ) : ?>
<button id="easypack_send_parcels" class="button button-primary"><?php _e('Send parcel', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php if ( $status == 'created' ) : ?>
<button id="easypack_cancel_parcels" class="button"><?php _e('Cancel parcels', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php if ( $status == 'ReadyToBeSent' || $status == 'prepared' ) : ?>
<a href="<?php echo $stickers_url; ?>" id="easypack_get_stickers" class="button button-primary" target="_blank"><?php _e('Get sticker(s)', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<?php if ( $tracking_url ) : ?>
<a href="<?php echo $tracking_url; ?>" class="button" target="_blank"><?php _e('Track shipment', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<?php if ( $status == 'Processing' ) : ?>
<?php _e( 'Processing', EasyPack::$text_domain ); ?>
<?php endif; ?>
<span id="easypack_spinner" class="spinner"></span>
</p>
<p id="easypack_error"></p>
<a href="#" download id="easypack_download" hidden></a>
<script type="text/javascript">
if ( jQuery().select2 ) {
jQuery("#parcel_machine_id").select2();
}
jQuery('#easypack_send_parcels').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var parcels = [];
jQuery('select.easypack_parcel_weight').each(function(i) {
var parent_div = jQuery(this).parent().parent();
parcels[i] = {
'weight' : jQuery(this).val(),
'width' : jQuery(parent_div).find('.easypack_parcel_width').val(),
'height' : jQuery(parent_div).find('.easypack_parcel_height').val(),
'length' : jQuery(parent_div).find('.easypack_parcel_length').val(),
};
})
var data = {
action: 'easypack',
easypack_action: 'crossborder_parcel_machines_create_package',
security: easypack_nonce,
order_id: <?php echo $order_id; ?>,
parcel_machine_id: jQuery('#parcel_machine_id').val(),
parcels: parcels,
send_method: jQuery('#easypack_send_method').val(),
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_send_parcels').attr('disabled',false);
});
return false;
});
function crossborder_processing() {
console.log(jQuery('#easypack_status').val());
if ( jQuery('#easypack_status').val() == 'Processing' ) {
jQuery("#easypack_spinner").addClass("is-active");
var data = {
action: 'easypack',
easypack_action: 'crossborder_parcel_machines_processing',
security: easypack_nonce,
order_id: <?php echo $order_id; ?>,
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
jQuery("#easypack_parcel_machines .inside").html(response.content);
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_cancel_parcels').attr('disabled',false);
});
}
}
crossborder_processing();
</script>

View File

@@ -0,0 +1,191 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$first_parcel = true;
?>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
woocommerce_wp_text_input([
'id' => 'parcel_machine_id',
'label' => __('Selected parcel locker', EasyPack::$text_domain ),
'desc_tip' => false,
'value' => $parcel_machine_id,
'custom_attributes' => $custom_attributes,
'class' => 'settings-geowidget',
]);
?>
<p><?php _e( 'Parcels', EasyPack::$text_domain ); ?>
<ol id="easypack_parcels">
<?php foreach ( $parcels as $parcel ) : ?>
<li>
<?php if ( $status == 'new' ) : ?>
<?php
$params = array(
'type' => 'select',
'options' => $package_sizes,
'class' => array('easypack_parcel'),
'input_class' => array('easypack_parcel'),
'label' => '',
);
woocommerce_form_field('parcel[]', $params, $parcel['package_size'] );
?>
<?php if ( $status == 'new' && ! $first_parcel ) : ?>
<button class="button easypack_remove_parcel"><?php _e( 'Remove', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php else : ?>
<?php _e( 'Size', EasyPack::$text_domain ); ?> <?php echo $package_sizes_display[$parcel['package_size']]; ?>:
<?php echo $parcel['easypack_data']['id']; ?>
<?php endif; ?>
</li>
<?php $first_parcel = false; ?>
<?php endforeach; ?>
</ol>
<?php if ( $status == 'new' ) : ?>
<button class="button easypack_add_parcel"><?php _e( 'Add parcel', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
</p>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled || $send_method_disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
$params = array(
'type' => 'select',
'options' => $send_methods,
'class' => array('wc-enhanced-select'),
'custom_attributes' => $custom_attributes,
'label' => __( 'Send method', EasyPack::$text_domain ),
);
woocommerce_form_field('easypack_send_method', $params, $send_method );
?>
<p>
<?php if ( $status == 'new' ) : ?>
<button id="easypack_send_parcels" class="button button-primary"><?php _e('Send parcels', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php if ( EasyPack_API()->api_country() == 'PL' ) : ?>
<?php if ( $status == 'created' ) : ?>
<button id="easypack_cancel_parcels" class="button"><?php _e('Cancel parcels', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php endif; ?>
<?php if ( EasyPack_API()->api_country() == 'PL' ) : ?>
<?php if ( $status == 'created' || $status == 'prepared' ) : ?>
<a href="<?php echo $stickers_url; ?>" id="easypack_get_stickers" class="button button-primary" target="_blank"><?php _e('Get sticker(s)', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<?php endif; ?>
<?php if ( false) : ?>
<a href="<?php echo $tracking_url; ?>" class="button" target="_blank"><?php _e('Track shipment', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<span id="easypack_spinner" class="spinner"></span>
</p>
<p id="easypack_error"></p>
<a href="#" download id="easypack_download" hidden></a>
<script type="text/javascript">
jQuery(".easypack_add_parcel").click(function() {
var ul = jQuery('#easypack_parcels');
var li = ul.find('li:first').clone(true)
li.append('<button class="button easypack_remove_parcel"><?php _e( 'Remove', EasyPack::$text_domain ); ?></button>');
li.appendTo(ul);
return false;
});
jQuery("#easypack_parcels").on("click", ".easypack_remove_parcel", function() {
jQuery(this).parent().remove();
return false;
})
jQuery('#easypack_send_parcels').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var parcels = [];
jQuery('select.easypack_parcel').each(function(i) {
parcels[i] = jQuery(this).val();
})
var data = {
action : 'easypack',
easypack_action : 'parcel_machines_create_package',
security : easypack_nonce,
order_id : <?php echo $order_id; ?>,
parcel_machine_id : jQuery('#parcel_machine_id').val(),
parcels : parcels,
send_method : jQuery('#easypack_send_method').val(),
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_send_parcels').attr('disabled',false);
});
return false;
});
jQuery('#easypack_cancel_parcels').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var data = {
action : 'easypack',
easypack_action : 'parcel_machines_cancel_package',
security : easypack_nonce,
order_id : <?php echo $order_id; ?>,
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_cancel_parcels').attr('disabled',false);
});
return false;
});
</script>

View File

@@ -0,0 +1,244 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$first_parcel = true;
?>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
woocommerce_wp_text_input([
'id' => 'parcel_machine_id',
'label' => __('Selected parcel locker', EasyPack::$text_domain ),
'desc_tip' => false,
'value' => $parcel_machine_id,
'custom_attributes' => $custom_attributes,
'class' => 'settings-geowidget',
]);
?>
<p><?php _e( 'Parcels', EasyPack::$text_domain ); ?>
<ol id="easypack_parcels">
<?php foreach ( $parcels as $parcel ) : ?>
<li>
<?php if ( $status == 'new' ) : ?>
<?php
$params = array(
'type' => 'select',
'options' => $package_sizes,
'class' => array('easypack_parcel'),
'input_class' => array('easypack_parcel'),
'label' => '',
);
woocommerce_form_field('parcel[]', $params, $parcel['package_size'] );
?>
<?php _e( 'COD amount: ', EasyPack::$text_domain ); ?>
<input class="easypack_cod_amount" type="number" style="" value="<?php echo $parcel['cod_amount']; ?>" placeholder="0.00" step="any" min="0" name="cod_amount[]">
<?php if ( $status == 'new' && ! $first_parcel ) : ?>
<button class="button easypack_remove_parcel"><?php _e( 'Remove', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php else : ?>
<?php _e( 'Size', EasyPack::$text_domain ); ?> <?php echo $package_sizes_display[$parcel['package_size']]; ?>:
<?php echo $parcel['easypack_data']['id']; ?><br/>
<?php _e( 'COD amount', EasyPack::$text_domain ); ?> <?php echo $parcel['easypack_data']['cod_amount']; ?>
<?php endif; ?>
</li>
<?php $first_parcel = false; ?>
<?php endforeach; ?>
</ol>
<?php if ( $status == 'new' ) : ?>
<button class="button easypack_add_parcel"><?php _e( 'Add parcel', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
</p>
<?php
$custom_attributes = array( 'style' => 'width:100%;' );
if ( $disabled || $send_method_disabled ) {
$custom_attributes['disabled'] = 'disabled';
}
$params = array(
'type' => 'select',
'options' => $send_methods,
'class' => array('wc-enhanced-select'),
'custom_attributes' => $custom_attributes,
'label' => __('Send method', EasyPack::$text_domain ),
);
woocommerce_form_field('easypack_send_method', $params, $send_method );
?>
<p>
<?php if ( $status == 'new' ) : ?>
<button id="easypack_send_parcels" class="button button-primary"><?php _e('Send parcels', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php if ( EasyPack_API()->api_country() == 'PL' ) : ?>
<?php if ( $status == 'created' ) : ?>
<button id="easypack_cancel_parcels" class="button"><?php _e('Cancel parcels', EasyPack::$text_domain ); ?></button>
<?php endif; ?>
<?php endif; ?>
<?php if ( EasyPack_API()->api_country() == 'PL' ) : ?>
<?php if ( $status == 'created' || $status == 'prepared' ) : ?>
<a href="<?php echo $stickers_url; ?>" id="easypack_get_stickers" class="button button-primary" target="_blank"><?php _e('Get sticker(s)', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<?php endif; ?>
<?php if ( $tracking_url ) : ?>
<a href="<?php echo $tracking_url; ?>" class="button" target="_blank"><?php _e('Track shipment', EasyPack::$text_domain ); ?></a>
<?php endif; ?>
<span id="easypack_spinner" class="spinner"></span>
</p>
<p id="easypack_error"></p>
<a href="#" download id="easypack_download" hidden></a>
<script type="text/javascript">
jQuery(".easypack_add_parcel").click(function() {
var ul = jQuery('#easypack_parcels');
var li = ul.find('li:first').clone(true)
li.append('<button class="button easypack_remove_parcel"><?php _e( 'Remove', EasyPack::$text_domain ); ?></button>');
li.appendTo(ul);
li.find(".easypack_cod_amount").val(0);
return false;
});
jQuery("#easypack_parcels").on("click", ".easypack_remove_parcel", function() {
jQuery(this).parent().remove();
return false;
})
jQuery('#easypack_send_parcels').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var parcels = [];
jQuery('select.easypack_parcel').each(function(i) {
parcels[i] = jQuery(this).val();
})
var cod_amounts = [];
jQuery('input.easypack_cod_amount').each(function(i) {
cod_amounts[i] = jQuery(this).val();
})
var data = {
action : 'easypack',
easypack_action : 'parcel_machines_cod_create_package',
security : easypack_nonce,
order_id : <?php echo $order_id; ?>,
parcel_machine_id : jQuery('#parcel_machine_id').val(),
parcels : parcels,
cod_amounts : cod_amounts,
send_method : jQuery('#easypack_send_method').val(),
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_send_parcels').attr('disabled',false);
});
return false;
});
jQuery('#easypack_cancel_parcels').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var data = {
action : 'easypack',
easypack_action : 'parcel_machines_cod_cancel_package',
security : easypack_nonce,
order_id : <?php echo $order_id; ?>,
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
jQuery("#easypack_parcel_machines .inside").html(response.content);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_cancel_parcels').attr('disabled',false);
});
return false;
});
jQuery('#easypack_get_stickers1').click(function () {
jQuery('#easypack_error').html('');
jQuery(this).attr('disabled',true);
jQuery("#easypack_spinner").addClass("is-active");
var data = {
action : 'easypack',
easypack_action : 'parcel_machines_get_stickers',
security : easypack_nonce,
order_id : <?php echo $order_id; ?>,
};
jQuery.post(ajaxurl, data, function(response) {
console.log(response);
if ( response != 0 ) {
response = JSON.parse(response);
console.log(response);
if (response.status == 'ok' ) {
var url = response.url;
//alert(url);
jQuery("#easypack_download").attr( "href", url );
jQuery("#easypack_download").click();
/*
if ( jQuery('#easypack_download').length ){
jQuery('#easypack_download').attr('src',url);
}
else {
jQuery('<iframe>', { id:'easypack_download', src:url }).hide().appendTo('body');
}
*/
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_get_stickers').attr('disabled',false);
return false;
}
else {
//alert(response.message);
jQuery('#easypack_error').html(response.message);
}
}
else {
//alert('Bad response.');
jQuery('#easypack_error').html('Invalid response.');
}
jQuery("#easypack_spinner").removeClass("is-active");
jQuery('#easypack_get_stickers').attr('disabled',false);
});
return false;
});
</script>

View File

@@ -0,0 +1,103 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$field = $this->get_field_key( $key );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="woocommerce_easypack-parcel-machines_rates"><?php echo $data['title']; ?></label>
</th>
<td class="forminp">
<table id="<?php echo esc_attr( $field ); ?>" class="easypack_rates wc_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th class="price"><?php _e( 'Min', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( 'Max', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( 'Cost', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '%', EasyPack::$text_domain ); ?>&nbsp;<span class="tips" data-tip="<?php esc_attr_e( 'The commission is added to the shipping cost according to the formula: [value of the cart] * [%] + [shipping cost].', EasyPack::$text_domain ); ?>">[?]</span></th>
<th class="action"><?php _e( 'Action', EasyPack::$text_domain ); ?></th>
</tr>
</thead>
<tbody>
<?php $count = 0; ?>
<?php foreach ( $rates as $key => $rate) : $count++; ?>
<tr>
<td class="sort"></td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['min']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][min]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['max']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][max]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['cost']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][cost]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['percent']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][percent]>
</td>
<td class="action">
<a id="delete_rate_<?php echo $count; ?>" href="#" class="button delete_rate" data-id="<?php echo $count; ?>"><?php _e( 'Delete row', EasyPack::$text_domain ); ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th colspan="6">
<a id="insert_rate" href="#" class="button plus insert"><?php _e( 'Insert row', EasyPack::$text_domain ); ?></a>
</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
function append_row( id ) {
var code = '<tr class="new">\
<td class="sort"></td>\
<td>\
<input id="rates_'+id+'_min" class="input-text regular-input" type="number" style="" value="" placeholder="0.00" step="any" min="0" name=rates[' + id + '][min]>\
</td>\
<td>\
<input class="input-text regular-input" type="number" style="" value="" placeholder="0.00" step="any" min="0" name=rates[' + id + '][max]>\
</td>\
<td>\
<input class="input-text regular-input" type="number" style="" value="" placeholder="0.00" step="any" min="0" name=rates[' + id + '][cost]>\
</td>\
<td>\
<input class="input-text regular-input" type="number" style="" value="<?php echo $commission; ?>" placeholder="0.00" step="any" min="0" name=rates[' + id + '][percent]>\
</td>\
<td>\
<a id="delete_rate_'+id+'" href="#" class="button delete_rate" data-id="'+id+'"><?php _e( 'Delete row', EasyPack::$text_domain ); ?></a>\
</td>\
</tr>';
var $tbody = jQuery('.easypack_rates').find('tbody');
$tbody.append( code );
}
jQuery(document).ready(function() {
var $tbody = jQuery('.easypack_rates').find('tbody');
var append_id = $tbody.find('tr').size();
var size = $tbody.find('tr').size();
if ( size == 0 ) {
append_id = append_id+1;
append_row(append_id);
}
jQuery('#insert_rate').click(function() {
append_id = append_id+1;
append_row(append_id);
jQuery('#rates_'+append_id+'_min').focus();
return false;
});
jQuery(document).on('click', '.delete_rate', function() {
if (confirm('<?php _e( 'Are you sure?' , EasyPack::$text_domain ); ?>')) {
jQuery(this).closest('tr').remove();
}
return false;
});
});
</script>
</td>
</tr>

View File

@@ -0,0 +1,64 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$field = $this->get_field_key( $key );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="woocommerce_easypack--cross-border-parcel-machines_rates"><?php echo $data['title']; ?></label>
<img class="help_tip" data-tip=" <?php _e( 'You can edit and set your own prices that will be seen when the customer is placing the order. If the products do not have a defined weight, the cost will be calculated incorrectly.', EasyPack::$text_domain ); ?>" src="<?php echo plugins_url( 'woocommerce/assets/images/help.png' ); ?>" height="16" width="16" />
</th>
<td class="forminp">
<table id="<?php echo esc_attr( $field ); ?>" class="easypack_rates wc_input_table sortable widefat">
<thead>
<tr>
<th class="country"><?php _e( 'Country', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '1 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '2 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '5 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '10 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '15 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '20 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '25 kg', EasyPack::$text_domain ); ?></th>
</tr>
</thead>
<tbody>
<?php $count = 0; ?>
<?php foreach ( $rates as $rate) : $count++; $key = $rate['country_code']; ?>
<tr>
<td class="country">
<strong><?php echo $countries[$key]; ?></strong>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_1']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_1]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_2']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_2]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_5']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_5]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_10']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_10]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_15']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_15]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_20']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_20]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_25']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_25]>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
</tfoot>
</table>
</td>
</tr>

View File

@@ -0,0 +1,63 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$field = $this->get_field_key( $key );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="woocommerce_easypack--cross-border-parcel-machines_rates"><?php echo $data['title']; ?></label>
<img class="help_tip" data-tip=" <?php _e( 'You can edit and set your own prices that will be seen when the customer is placing the order. If the products do not have a defined weight, the cost will be calculated incorrectly.', EasyPack::$text_domain ); ?>" src="<?php echo plugins_url( 'woocommerce/assets/images/help.png' ); ?>" height="16" width="16" />
</th>
<td class="forminp">
<table id="<?php echo esc_attr( $field ); ?>" class="easypack_rates wc_input_table sortable widefat">
<thead>
<tr>
<th class="country"><?php _e( 'Country', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '1 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '2 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '5 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '10 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '15 kg', EasyPack::$text_domain ); ?></th>
<th class="price"><?php _e( '20 kg', EasyPack::$text_domain ); ?></th>
</tr>
</thead>
<tbody>
<?php $count = 0; ?>
<?php foreach ( $rates as $key => $rate) : $count++; ?>
<tr>
<td class="country">
<strong><?php echo $countries[$key]; ?></strong>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_1']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_1]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_2']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_2]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_5']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_5]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_10']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_10]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_15']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_15]>
</td>
<td class="price">
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['kg_20']; ?>" placeholder="0.00" step="any" min="0" name=rates[<?php echo $key; ?>][kg_20]>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
</tfoot>
</table>
</td>
</tr>

View File

@@ -0,0 +1,99 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
$field = $this->get_field_key( $key );
?>
<tr valign="top">
<th scope="row" class="titledesc">
<label for="woocommerce_easypack_parcel_machines_rates"><?php echo $data['title']; ?></label>
</th>
<td class="forminp">
<table id="<?php echo esc_attr( $field ); ?>" class="easypack_rates wc_input_table sortable widefat">
<thead>
<tr>
<th class="sort">&nbsp;</th>
<th><?php _e( 'Min', EasyPack::$text_domain ); ?></th>
<th><?php _e( 'Max', EasyPack::$text_domain ); ?></th>
<th><?php _e( 'Cost', EasyPack::$text_domain ); ?></th>
<th><?php _e( 'Action', EasyPack::$text_domain ); ?></th>
</tr>
</thead>
<tbody>
<?php $count = 0; ?>
<?php foreach ( $rates as $key => $rate) : $count++; ?>
<tr>
<td class="sort"></td>
<td>
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['min']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][min]>
</td>
<td>
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['max']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][max]>
</td>
<td>
<input class="input-text regular-input" type="number" style="" value="<?php echo $rate['cost']; ?>" placeholder="0.00" step="any" min="0" name=rates['<?php echo $count; ?>'][cost]>
</td>
<td>
<a id="delete_rate_<?php echo $count; ?>" href="#" class="button delete_rate" data-id="<?php echo $count; ?>"><?php _e( 'Delete row', EasyPack::$text_domain ); ?></a>
</td>
</tr>
<?php endforeach; ?>
</tbody>
<tfoot>
<tr>
<th colspan="5">
<a id="insert_rate" href="#" class="button plus insert"><?php _e( 'Insert row', EasyPack::$text_domain ); ?></a>
</th>
</tr>
</tfoot>
</table>
<script type="text/javascript">
function append_row( id ) {
var code = '<tr class="new">\
<td class="sort"></td>\
<td>\
<input id="rates_'+id+'_min" class="input-text regular-input" type="number" style="" value="" placeholder="0.00" step="any" min="0" name=rates[' + id + '][min]>\
</td>\
<td>\
<input class="input-text regular-input" type="number" style="" value="" placeholder="0.00" step="any" min="0" name=rates[' + id + '][max]>\
</td>\
<td>\
<input class="input-text regular-input" type="number" style="" value="" placeholder="0.00" step="any" min="0" name=rates[' + id + '][cost]>\
</td>\
<td>\
<a id="delete_rate_'+id+'" href="#" class="button delete_rate" data-id="'+id+'"><?php _e( 'Delete row', EasyPack::$text_domain ); ?></a>\
</td>\
</tr>';
var $tbody = jQuery('.easypack_rates').find('tbody');
$tbody.append( code );
}
jQuery(document).ready(function() {
var $tbody = jQuery('.easypack_rates').find('tbody');
var append_id = $tbody.find('tr').size();
var size = $tbody.find('tr').size();
if ( size == 0 ) {
append_id = append_id+1;
append_row(append_id);
}
jQuery('#insert_rate').click(function() {
append_id = append_id+1;
append_row(append_id);
jQuery('#rates_'+append_id+'_min').focus();
return false;
});
jQuery(document).on('click', '.delete_rate', function() {
if (confirm('<?php _e( 'Are you sure?' , EasyPack::$text_domain ); ?>')) {
jQuery(this).closest('tr').remove();
}
return false;
});
});
</script>
</td>
</tr>