Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| BH_WC_Postcode_Address_Autofill | |
100.00% |
20 / 20 |
|
100.00% |
6 / 6 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| set_locale | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| define_woocommerce_countries_hooks | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| define_woocommerce_shortcode_checkout_hooks | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| define_woocommerce_blocks_checkout_hooks | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| define_woocommerce_features_hooks | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * The file that defines the actions and filters for the plugin. |
| 4 | * |
| 5 | * @package brianhenryie/bh-wc-postcode-address-autofill |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\WC_Postcode_Address_Autofill; |
| 9 | |
| 10 | use BrianHenryIE\WC_Postcode_Address_Autofill\WooCommerce\Blocks; |
| 11 | use BrianHenryIE\WC_Postcode_Address_Autofill\WooCommerce\Countries; |
| 12 | use BrianHenryIE\WC_Postcode_Address_Autofill\WooCommerce\Checkout_Blocks; |
| 13 | use BrianHenryIE\WC_Postcode_Address_Autofill\WooCommerce\Checkout_Shortcode; |
| 14 | use BrianHenryIE\WC_Postcode_Address_Autofill\WooCommerce\Features; |
| 15 | use BrianHenryIE\WC_Postcode_Address_Autofill\WP_Includes\I18n; |
| 16 | |
| 17 | /** |
| 18 | * The core plugin class. |
| 19 | * |
| 20 | * This is used to define internationalization, admin-specific hooks, and |
| 21 | * frontend-facing site hooks. |
| 22 | */ |
| 23 | class BH_WC_Postcode_Address_Autofill { |
| 24 | |
| 25 | /** |
| 26 | * The plugin settings. |
| 27 | */ |
| 28 | protected Settings_Interface $settings; |
| 29 | |
| 30 | /** |
| 31 | * The main plugin functions. |
| 32 | */ |
| 33 | protected API_Interface $api; |
| 34 | |
| 35 | /** |
| 36 | * Constructor |
| 37 | * |
| 38 | * @param API_Interface $api The main plugin functions. |
| 39 | * @param Settings_Interface $settings The plugin settings. |
| 40 | */ |
| 41 | public function __construct( API_Interface $api, Settings_Interface $settings ) { |
| 42 | |
| 43 | $this->settings = $settings; |
| 44 | $this->api = $api; |
| 45 | |
| 46 | $this->set_locale(); |
| 47 | |
| 48 | $this->define_woocommerce_countries_hooks(); |
| 49 | $this->define_woocommerce_shortcode_checkout_hooks(); |
| 50 | $this->define_woocommerce_blocks_checkout_hooks(); |
| 51 | $this->define_woocommerce_features_hooks(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Define the locale for this plugin for internationalization. |
| 56 | * |
| 57 | * Uses the i18n class in order to set the domain and to register the hook |
| 58 | * with WordPress. |
| 59 | */ |
| 60 | protected function set_locale(): void { |
| 61 | |
| 62 | $plugin_i18n = new I18n(); |
| 63 | |
| 64 | add_action( 'init', array( $plugin_i18n, 'load_plugin_textdomain' ) ); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Define the WooCommerce checkout hooks. |
| 69 | */ |
| 70 | protected function define_woocommerce_countries_hooks(): void { |
| 71 | |
| 72 | $countries = new Countries(); |
| 73 | |
| 74 | add_filter( 'woocommerce_get_country_locale', array( $countries, 'add_postcode_priority_to_country_locale' ) ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Register hooks for operation on traditional WooCommerce "shortcode" checkout. |
| 79 | * Enqueue the required JavaScript and handle the checkout update. |
| 80 | */ |
| 81 | protected function define_woocommerce_shortcode_checkout_hooks(): void { |
| 82 | $woocommerce_shortcode_checkout = new Checkout_Shortcode( $this->api, $this->settings ); |
| 83 | |
| 84 | add_action( 'wp_enqueue_scripts', array( $woocommerce_shortcode_checkout, 'enqueue_scripts' ) ); |
| 85 | add_action( 'woocommerce_checkout_update_order_review', array( $woocommerce_shortcode_checkout, 'parse_post_on_update_order_review' ) ); |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Register hooks for operation on the WooCommerce Blocks checkout. |
| 90 | * Use IntegrationsRegistry to enqueue the script and Store API to handle updates from JavaScript. |
| 91 | */ |
| 92 | protected function define_woocommerce_blocks_checkout_hooks(): void { |
| 93 | $blocks = new Blocks( $this->api, $this->settings ); |
| 94 | |
| 95 | add_action( 'woocommerce_blocks_checkout_block_registration', array( $blocks, 'register_integration' ) ); |
| 96 | add_action( 'woocommerce_blocks_loaded', array( $blocks, 'register_update_callback' ) ); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Declare compatibility with WooCommerce features: High Performance Order Storage and Checkout Blocks. |
| 101 | */ |
| 102 | protected function define_woocommerce_features_hooks(): void { |
| 103 | |
| 104 | $features = new Features( $this->settings ); |
| 105 | |
| 106 | add_action( 'before_woocommerce_init', array( $features, 'declare_cart_checkout_blocks_compatibility' ) ); |
| 107 | add_action( 'before_woocommerce_init', array( $features, 'declare_hpos_compatibility' ) ); |
| 108 | } |
| 109 | } |