Skip to content

Commit

Permalink
Move pickup delivery admin fields to pickup delivery class. Added Woo…
Browse files Browse the repository at this point in the history
… < 8.6.0 backwards compatibility for admin fields.
  • Loading branch information
dennisnissle committed Apr 18, 2024
1 parent fd4de94 commit 4ed903d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 33 deletions.
30 changes: 0 additions & 30 deletions src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ function() {
add_action( 'woocommerce_admin_field_dimensions', array( __CLASS__, 'register_dimensions_field' ), 30 );
add_filter( 'woocommerce_admin_settings_sanitize_option', array( __CLASS__, 'sanitize_dimensions_field' ), 10, 3 );

add_filter( 'woocommerce_admin_shipping_fields', array( __CLASS__, 'register_pickup_location_admin_fields' ), 10, 3 );

add_filter( 'woocommerce_debug_tools', array( __CLASS__, 'register_remove_duplicate_provider_meta_tool' ), 10, 1 );
}

Expand Down Expand Up @@ -138,34 +136,6 @@ public static function remove_duplicate_provider_meta() {
}
}

public static function register_pickup_location_admin_fields( $fields, $order = null, $context = 'edit' ) {
if ( ! $order instanceof \WC_Order ) {
return $fields;
}

$shipment_order = wc_gzd_get_shipment_order( $order );

if ( $shipment_order->supports_pickup_location() ) {
$fields['pickup_location_code'] = array(
'label' => _x( 'Pickup location', 'shipments', 'woocommerce-germanized-shipments' ),
'type' => 'text',
'id' => '_pickup_location_code',
'show' => false,
'value' => $shipment_order->get_pickup_location_code(),
);

$fields['pickup_location_customer_number'] = array(
'label' => _x( 'Pickup customer number', 'shipments', 'woocommerce-germanized-shipments' ),
'show' => false,
'id' => '_pickup_location_customer_number',
'type' => 'text',
'value' => $shipment_order->get_pickup_location_customer_number(),
);
}

return $fields;
}

public static function sanitize_toggle_field( $value, $option, $raw_value ) {
if ( Package::is_integration() ) {
return $value;
Expand Down
6 changes: 3 additions & 3 deletions src/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function get_return_status() {
}

public function get_default_return_shipping_provider() {
$default_provider_instance = wc_gzd_get_order_shipping_provider( $this->get_order() );
$default_provider_instance = $this->get_shipping_provider();
$default_provider = $default_provider_instance ? $default_provider_instance->get_name() : '';
$shipments = $this->get_simple_shipments();

Expand Down Expand Up @@ -282,7 +282,7 @@ public function create_shipments( $default_status = 'processing' ) {
} else {
$available_packaging = wc_gzd_get_packaging_list();

if ( $provider = wc_gzd_get_order_shipping_provider( $this ) ) {
if ( $provider = $this->get_shipping_provider() ) {
$available_packaging = wc_gzd_get_packaging_list( array( 'shipping_provider' => $provider->get_name() ) );
}

Expand Down Expand Up @@ -1127,7 +1127,7 @@ public function get_returnable_item_count() {
public function supports_pickup_location() {
$supports_pickup_location = false;

if ( $provider = wc_gzd_get_order_shipping_provider( $this ) ) {
if ( $provider = $this->get_shipping_provider() ) {
if ( is_a( $provider, 'Vendidero\Germanized\Shipments\Interfaces\ShippingProviderAuto' ) ) {
$supports_pickup_location = $provider->supports_pickup_location_delivery( $this->get_order()->get_address( 'shipping' ) );
}
Expand Down
38 changes: 38 additions & 0 deletions src/PickupDelivery.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,44 @@ public static function init() {

add_filter( 'woocommerce_form_field_wc_gzd_shipments_pickup_location', array( __CLASS__, 'register_pickup_location_field' ), 10, 4 );
add_filter( 'woocommerce_form_field_wc_gzd_shipments_pickup_location_customer_number', array( __CLASS__, 'register_pickup_location_customer_number_field' ), 10, 4 );

add_filter( 'woocommerce_admin_shipping_fields', array( __CLASS__, 'register_pickup_location_admin_fields' ), 10, 3 );
}

public static function register_pickup_location_admin_fields( $fields, $order = null, $context = 'edit' ) {
if ( is_null( $order ) && version_compare( wc()->version, '8.6.0', '<' ) ) {
global $theorder;

if ( isset( $theorder ) ) {
$order = $theorder;
}
}

if ( ! $order instanceof \WC_Order ) {
return $fields;
}

if ( $shipment_order = wc_gzd_get_shipment_order( $order ) ) {
if ( $shipment_order->supports_pickup_location() ) {
$fields['pickup_location_code'] = array(
'label' => _x( 'Pickup location', 'shipments', 'woocommerce-germanized-shipments' ),
'type' => 'text',
'id' => '_pickup_location_code',
'show' => false,
'value' => $shipment_order->get_pickup_location_code(),
);

$fields['pickup_location_customer_number'] = array(
'label' => _x( 'Pickup customer number', 'shipments', 'woocommerce-germanized-shipments' ),
'show' => false,
'id' => '_pickup_location_customer_number',
'type' => 'text',
'value' => $shipment_order->get_pickup_location_customer_number(),
);
}
}

return $fields;
}

public static function register_pickup_location_customer_number_field( $field, $key, $args, $value ) {
Expand Down

0 comments on commit 4ed903d

Please sign in to comment.