| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; |
| 4 |
} |
| 5 |
|
| 6 |
class Routeapp_Integration_With_CheckoutWc { |
| 7 |
public function __construct() { |
| 8 |
if ($this->is_active()) { |
| 9 |
add_action( 'woocommerce_init', [ $this, 'actions' ] ); |
| 10 |
} |
| 11 |
} |
| 12 |
|
| 13 |
public function actions() { |
| 14 |
add_filter( 'wfacp_advanced_fields', function($field) { |
| 15 |
$field['route_widget_field'] = [ |
| 16 |
'type' => 'hidden', |
| 17 |
'default' => true, |
| 18 |
'label' => 'Route Widget', |
| 19 |
'validate' => [], |
| 20 |
'id' => 'route_widget_field', |
| 21 |
'required' => false, |
| 22 |
'wrapper_class' => [], |
| 23 |
'class' => [ 'route-widget-field' ], |
| 24 |
]; |
| 25 |
return $field; |
| 26 |
} ); |
| 27 |
|
| 28 |
add_filter( 'woocommerce_form_field_args', function( $args, $key ) { |
| 29 |
if ( $key == 'route_widget_field' ) { |
| 30 |
echo do_shortcode('[route]'); |
| 31 |
} |
| 32 |
return $args; |
| 33 |
}, 10, 2 ); |
| 34 |
} |
| 35 |
|
| 36 |
public function is_active() { |
| 37 |
$active_plugins = (array) get_option( 'active_plugins', array() ); |
| 38 |
|
| 39 |
if ( is_multisite() ) { |
| 40 |
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); |
| 41 |
} |
| 42 |
|
| 43 |
return in_array( 'checkout-for-woocommerce/checkout-for-woocommerce.php', $active_plugins ) || array_key_exists( 'checkout-for-woocommerce/checkout-for-woocommerce.php', $active_plugins ); |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
Routeapp_Plugin_Integrations::register( new Routeapp_Integration_With_CheckoutWc(), 'checkout-for-woocommerce' ); |
| 48 |
|