260 lines
12 KiB
PHP
260 lines
12 KiB
PHP
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
|
|
|
if ( ! class_exists( 'WPDesk_WooCommerce_DPD_FS_Hooks' ) ) {
|
|
|
|
class WPDesk_WooCommerce_DPD_FS_Hooks {
|
|
|
|
private $plugin = null;
|
|
|
|
public function __construct( WPDesk_WooCommerce_DPD_Plugin $plugin ) {
|
|
|
|
$this->plugin = $plugin;
|
|
|
|
add_filter( 'flexible_shipping_integration_options', array( $this, 'flexible_shipping_integration_options' ), 10 );
|
|
|
|
add_filter( 'flexible_shipping_method_settings', array( $this, 'flexible_shipping_method_settings' ), 10, 2 );
|
|
|
|
add_action( 'flexible_shipping_method_script', array( $this, 'flexible_shipping_method_script' ) );
|
|
|
|
add_filter( 'flexible_shipping_process_admin_options', array( $this, 'flexible_shipping_process_admin_options' ), 10, 1 );
|
|
|
|
add_filter( 'flexible_shipping_method_integration_col', array( $this, 'flexible_shipping_method_integration_col' ), 10, 2 );
|
|
|
|
add_filter( 'flexible_shipping_method_rate_id', array( $this, 'flexible_shipping_method_rate_id' ), 10, 2 );
|
|
|
|
add_filter( 'flexible_shipping_add_method', array( $this, 'flexible_shipping_add_method' ), 10, 3 );
|
|
|
|
}
|
|
|
|
function flexible_shipping_integration_options( $options ) {
|
|
$options['dpd'] = __( 'DPD', 'woocommerce-dpd' );
|
|
return $options;
|
|
}
|
|
|
|
public function flexible_shipping_method_settings( $flexible_shipping_settings, $shipping_method ) {
|
|
$shipping_methods = WC()->shipping->get_shipping_methods();
|
|
if ( 1 == 1 || $shipping_methods['dpd']->enabled == 'yes' ) { // always available
|
|
$declared_value_custom_attributes = array();
|
|
if ( isset( $shipping_method['dpd_declared_value'] ) && $shipping_method['dpd_declared_value'] == '1' ) {
|
|
$declared_value_custom_attributes = array( 'checked' => 'checked' );
|
|
}
|
|
$cod_custom_attributes = array();
|
|
if ( isset( $shipping_method['dpd_cod'] ) && $shipping_method['dpd_cod'] == '1' ) {
|
|
$cod_custom_attributes = array( 'checked' => 'checked' );
|
|
}
|
|
|
|
$saturday_custom_attributes = array();
|
|
if ( isset( $shipping_method['dpd_saturday'] ) && $shipping_method['dpd_saturday'] == '1' ) {
|
|
$saturday_custom_attributes = array( 'checked' => 'checked' );
|
|
}
|
|
|
|
$next_day_custom_attributes = array();
|
|
if ( isset( $shipping_method['dpd_next_day'] ) && $shipping_method['dpd_next_day'] == '1' ) {
|
|
$next_day_custom_attributes = array( 'checked' => 'checked' );
|
|
}
|
|
|
|
$pickup_custom_attributes = array();
|
|
if ( isset( $shipping_method['dpd_pickup'] ) && (int) $shipping_method['dpd_pickup'] === 1 ) {
|
|
$pickup_custom_attributes = array( 'checked' => 'checked' );
|
|
}
|
|
$settings = array(
|
|
'dpd_product' => array(
|
|
'title' => __( 'Usługa DPD', 'woocommerce-dpd' ),
|
|
'type' => 'select',
|
|
'default' => isset( $shipping_method['dpd_product'] ) ? $shipping_method['dpd_product'] : '',
|
|
'options' => WPDesk_WooCommerce_DPD::get_products(),
|
|
),
|
|
'dpd_package_settings' => array(
|
|
'title' => __( 'Domyślne ustawienia paczki', 'woocommerce-dpd' ),
|
|
'type' => 'title',
|
|
),
|
|
'dpd_package_width' => array(
|
|
'title' => __( 'Długość [cm]', 'woocommerce-dpd' ),
|
|
'type' => 'number',
|
|
'default' => isset( $shipping_method['dpd_package_width'] ) ? $shipping_method['dpd_package_width'] : '',
|
|
'custom_attributes' => array(
|
|
'step' => 'any'
|
|
)
|
|
),
|
|
'dpd_package_height' => array(
|
|
'title' => __( 'Wysokość [cm]', 'woocommerce-dpd' ),
|
|
'type' => 'number',
|
|
'default' => isset( $shipping_method['dpd_package_height'] ) ? $shipping_method['dpd_package_height'] : '',
|
|
'custom_attributes' => array(
|
|
'step' => 'any'
|
|
)
|
|
),
|
|
'dpd_package_depth' => array(
|
|
'title' => __( 'Głębokość [cm]', 'woocommerce-dpd' ),
|
|
'type' => 'number',
|
|
'default' => isset( $shipping_method['dpd_package_depth'] ) ? $shipping_method['dpd_package_depth'] : '',
|
|
'custom_attributes' => array(
|
|
'step' => 'any'
|
|
)
|
|
),
|
|
'dpd_package_content' => array(
|
|
'title' => __( 'Zawartość', 'woocommerce-dpd' ),
|
|
'default' => isset( $shipping_method['dpd_package_content'] ) ? $shipping_method['dpd_package_content'] : '',
|
|
'type' => 'text',
|
|
),
|
|
'dpd_declared_value' => array(
|
|
'title' => __( 'Zadeklarowana wartość', 'woocommerce-dpd' ),
|
|
'type' => 'checkbox',
|
|
'custom_attributes' => $declared_value_custom_attributes
|
|
),
|
|
'dpd_cod' => array(
|
|
'title' => __( 'Pobranie', 'woocommerce-dpd' ),
|
|
'type' => 'checkbox',
|
|
'custom_attributes' => $cod_custom_attributes
|
|
),
|
|
'dpd_pickup' => array(
|
|
'title' => __( 'Doręczenie do punktu odbioru', 'woocommerce-dpd' ),
|
|
'type' => 'checkbox',
|
|
'custom_attributes' => $pickup_custom_attributes
|
|
),
|
|
'dpd_saturday' => array(
|
|
'title' => __( 'Doręczenie w sobotę', 'woocommerce-dpd' ),
|
|
'type' => 'checkbox',
|
|
'custom_attributes' => $saturday_custom_attributes
|
|
),
|
|
'dpd_next_day' => array(
|
|
'title' => __( 'DPD Next Day', 'woocommerce-dpd' ),
|
|
'label' => __( 'Dostawa następnego dnia', 'woocommerce-dpd' ),
|
|
'type' => 'checkbox',
|
|
'custom_attributes' => $next_day_custom_attributes
|
|
),
|
|
);
|
|
return array_merge( $flexible_shipping_settings, $settings );
|
|
}
|
|
return $flexible_shipping_settings;
|
|
}
|
|
|
|
public function flexible_shipping_method_script() {
|
|
?>
|
|
<script type="text/javascript">
|
|
jQuery(document).ready(function() {
|
|
function dpdOptions() {
|
|
if ( jQuery('#woocommerce_flexible_shipping_method_integration').val() == 'dpd' ) {
|
|
jQuery('#woocommerce_flexible_shipping_dpd_product').closest('tr').css('display','none');
|
|
//jQuery('#woocommerce_flexible_shipping_dpd_product').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_settings').css('display','block');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_width').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_height').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_depth').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_content').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_declared_value').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_cod').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_saturday').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_next_day').closest('tr').css('display','table-row');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_pickup').closest('tr').css('display','table-row');
|
|
}
|
|
else {
|
|
jQuery('#woocommerce_flexible_shipping_dpd_product').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_settings').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_width').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_height').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_depth').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_package_content').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_declared_value').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_cod').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_saturday').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_next_day').closest('tr').css('display','none');
|
|
jQuery('#woocommerce_flexible_shipping_dpd_pickup').closest('tr').css('display','none');
|
|
}
|
|
}
|
|
jQuery('#woocommerce_flexible_shipping_method_integration').change(function() {
|
|
dpdOptions();
|
|
});
|
|
jQuery('#woocommerce_flexible_shipping_dpd_product').change(function() {
|
|
dpdOptions();
|
|
});
|
|
dpdOptions();
|
|
});
|
|
</script>
|
|
<?php
|
|
}
|
|
|
|
public function flexible_shipping_process_admin_options( $shipping_method ) {
|
|
$shipping_method['dpd_product'] = $_POST['woocommerce_flexible_shipping_dpd_product'];
|
|
$shipping_method['dpd_package_width'] = $_POST['woocommerce_flexible_shipping_dpd_package_width'];
|
|
$shipping_method['dpd_package_height'] = $_POST['woocommerce_flexible_shipping_dpd_package_height'];
|
|
$shipping_method['dpd_package_depth'] = $_POST['woocommerce_flexible_shipping_dpd_package_depth'];
|
|
$shipping_method['dpd_package_content'] = $_POST['woocommerce_flexible_shipping_dpd_package_content'];
|
|
|
|
$shipping_method['dpd_declared_value'] = 0;
|
|
if ( isset( $_POST['woocommerce_flexible_shipping_dpd_declared_value'] ) ) {
|
|
$shipping_method['dpd_declared_value'] = $_POST['woocommerce_flexible_shipping_dpd_declared_value'];
|
|
}
|
|
$shipping_method['dpd_cod'] = 0;
|
|
if ( isset( $_POST['woocommerce_flexible_shipping_dpd_cod'] ) ) {
|
|
$shipping_method['dpd_cod'] = $_POST['woocommerce_flexible_shipping_dpd_cod'];
|
|
}
|
|
|
|
$shipping_method['dpd_saturday'] = 0;
|
|
if ( isset( $_POST['woocommerce_flexible_shipping_dpd_saturday'] ) ) {
|
|
$shipping_method['dpd_saturday'] = $_POST['woocommerce_flexible_shipping_dpd_saturday'];
|
|
}
|
|
|
|
$shipping_method['dpd_next_day'] = 0;
|
|
if ( isset( $_POST['woocommerce_flexible_shipping_dpd_next_day'] ) ) {
|
|
$shipping_method['dpd_next_day'] = $_POST['woocommerce_flexible_shipping_dpd_next_day'];
|
|
}
|
|
|
|
return $shipping_method;
|
|
}
|
|
|
|
public function flexible_shipping_method_integration_col( $col, $shipping_method ) {
|
|
$shipping_methods = WC()->shipping->get_shipping_methods();
|
|
if ( $shipping_methods['dpd']->enabled == 'yes' ) {
|
|
if ( isset( $shipping_method['method_integration'] ) && 'dpd' === $shipping_method['method_integration'] ) {
|
|
ob_start();
|
|
$tip = __( 'Brak', 'woocommerce-dpd' );
|
|
$products = WPDesk_WooCommerce_dpd::get_products();
|
|
if ( isset( $products[$shipping_method['dpd_product']] ) ) {
|
|
$tip = $products[$shipping_method['dpd_product']];
|
|
}
|
|
/*
|
|
$package_types = WPDesk_WooCommerce_DPD::get_package_types();
|
|
if ( isset( $package_types[$shipping_method['dpd_package_type']] ) ) {
|
|
$tip .= ', ' . $package_types[$shipping_method['dpd_package_type']];
|
|
}
|
|
*/
|
|
?>
|
|
<td width="1%" class="integration default">
|
|
<span class="tips" data-tip="<?php echo $tip; ?>">
|
|
<?php echo $shipping_methods['dpd']->title; ?>
|
|
</span>
|
|
</td>
|
|
<?php
|
|
$col = ob_get_contents();
|
|
ob_end_clean();
|
|
}
|
|
}
|
|
return $col;
|
|
}
|
|
|
|
public function flexible_shipping_method_rate_id( $rate_id, $shipping_method ) {
|
|
if ( isset( $shipping_method['method_integration'] ) && 'dpd' === $shipping_method['method_integration'] ) {
|
|
//$rate_id = $rate_id . '_dpd_' . sanitize_title( $shipping_method['dpd_product'] ) . '_' . $shipping_method['dpd_package_type'] . '_' . $shipping_method['dpd_insurance'];
|
|
$rate_id = $rate_id . '_dpd_' . sanitize_title( $shipping_method['dpd_product'] );
|
|
if ( isset( $shipping_method['dpd_cod'] ) ) {
|
|
$rate_id .= '_' . $shipping_method['dpd_cod'];
|
|
}
|
|
}
|
|
return $rate_id;
|
|
}
|
|
|
|
public function flexible_shipping_add_method( $add_method, $shipping_method, $package ) {
|
|
if ( isset( $shipping_method['method_integration'] ) && 'dpd' === $shipping_method['method_integration']
|
|
&& isset( $shipping_method['dpd_product'] )
|
|
) {
|
|
}
|
|
return $add_method;
|
|
}
|
|
|
|
}
|
|
|
|
}
|