-
Notifications
You must be signed in to change notification settings - Fork 0
/
iconic-woo-delivery-slots-compat-custom-shipping.php
48 lines (42 loc) · 1.55 KB
/
iconic-woo-delivery-slots-compat-custom-shipping.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Plugin Name: WooCommerce Delivery Slots by Iconic [Custom Shipping Methods for WooCommerce]
* Plugin URI: https://iconicwp.com/products/woocommerce-delivery-slots/
* Description: Compatibility between WooCommerce Delivery Slots by Iconic and Custom Shipping Methods for WooCommerce by Tyche Softwares.
* Author: Iconic
* Author URI: https://iconicwp.com/
* Text Domain: iconic-woo-delivery-slots-compat-custom-shipping-methods
* Domain Path: /languages
* Version: 0.1.0
*
* @package Iconic_Woo_Delivery_Slots_Compat_Custom_Shipping_Methods
*/
/**
* Is WooCommerce Custom Shipping Methods active?
*
* @return bool
*/
function iconic_compat_custom_shipping_is_active() {
return class_exists( 'Alg_WC_Custom_Shipping_Methods' );
}
/**
* Change the format of shipping method ID.
*
* @return array
*/
function iconic_compat_custom_shipping_replace_shipping_method_id( $shipping_method_options ) {
if ( ! iconic_compat_custom_shipping_is_active() ) {
return $shipping_method_options;
}
foreach ( $shipping_method_options as $key => $method_name ) {
if ( 'alg_custom:' === substr( $key, 0, 11 ) ) {
$parts = explode( ':', $key );
$instance_id = $parts[1];
$new_key = sprintf( 'alg_wc_shipping:%d', $instance_id );
unset( $shipping_method_options[ $key ] );
$shipping_method_options[ $new_key ] = $method_name;
}
}
return $shipping_method_options;
}
add_filter( 'iconic_wds_shipping_method_options', 'iconic_compat_custom_shipping_replace_shipping_method_id', 10 );