includes(); $this->init_hooks(); } private function includes(): void { // Model + fee engine: needed on both frontend and admin. require_once XFEE_PLUGIN_PATH . 'admin/model.php'; require_once XFEE_PLUGIN_PATH . 'front/class-fee.php'; if ( is_admin() ) { require_once XFEE_PLUGIN_PATH . 'system/library/ocm/autoloader.php'; require_once XFEE_PLUGIN_PATH . 'admin/controller.php'; new XFee_Back( new XFee_Model() ); } } private function init_hooks(): void { // Translations load automatically on WP 4.6+ (slug = text domain = "extnify-fee"), // so no load_plugin_textdomain() call is needed. // // Fees are added to the cart/checkout totals via woocommerce_cart_calculate_fees. // The engine reads the shared methods table and calls WC()->cart->add_fee(). add_action( 'woocommerce_cart_calculate_fees', array( $this, 'calculate_fees' ) ); } /** * Apply matching fees to the cart. WooCommerce fires this during totals * calculation (cart + checkout); the fee engine owns all the logic. */ public function calculate_fees( $cart ): void { if ( is_admin() && ! defined( 'DOING_AJAX' ) ) { return; } if ( ! $cart instanceof WC_Cart || $cart->is_empty() ) { return; } ( new XFee_Fee() )->apply( $cart ); } }