Initial commit of the Woo Alipay - Face To Face (F2F) extension for WooCommerce. Adds independent Alipay F2F (QR code) payment gateway, supporting WooCommerce Blocks, custom styles, scripts, and admin settings integration. Includes gateway class, Blocks support, frontend assets, and template for QR code payment page.
48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) { exit; }
|
|
|
|
// Define extension path/url constants
|
|
if ( ! defined( 'WOO_ALIPAY_F2F_PLUGIN_FILE' ) ) {
|
|
define( 'WOO_ALIPAY_F2F_PLUGIN_FILE', __FILE__ );
|
|
}
|
|
if ( ! defined( 'WOO_ALIPAY_F2F_PLUGIN_PATH' ) ) {
|
|
define( 'WOO_ALIPAY_F2F_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
|
|
}
|
|
if ( ! defined( 'WOO_ALIPAY_F2F_PLUGIN_URL' ) ) {
|
|
define( 'WOO_ALIPAY_F2F_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
|
}
|
|
|
|
// Ensure WooCommerce and core Woo Alipay are active before loading classes
|
|
add_action( 'plugins_loaded', function () {
|
|
if ( class_exists( 'WC_Payment_Gateway' ) && class_exists( 'Woo_Alipay' ) ) {
|
|
// Load gateway class from this extension
|
|
$gateway_file = WOO_ALIPAY_F2F_PLUGIN_PATH . 'inc/class-wc-alipay-facetopay.php';
|
|
if ( file_exists( $gateway_file ) ) {
|
|
require_once $gateway_file;
|
|
}
|
|
}
|
|
}, 15 );
|
|
|
|
// Register gateway into WooCommerce (core will no longer add extension gateways)
|
|
add_filter( 'woocommerce_payment_gateways', function( $methods ) {
|
|
if ( class_exists( 'WC_Alipay_FaceToPay' ) ) {
|
|
$methods[] = 'WC_Alipay_FaceToPay';
|
|
}
|
|
return $methods;
|
|
}, 11, 1 );
|
|
|
|
// Register Blocks support from this extension
|
|
add_action(
|
|
'woocommerce_blocks_payment_method_type_registration',
|
|
function( Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry $registry ) {
|
|
$file = WOO_ALIPAY_F2F_PLUGIN_PATH . 'inc/class-wc-alipay-facetopay-blocks-support.php';
|
|
if ( file_exists( $file ) ) {
|
|
require_once $file;
|
|
}
|
|
if ( class_exists( 'WC_Alipay_FaceToPay_Blocks_Support' ) ) {
|
|
$registry->register( new WC_Alipay_FaceToPay_Blocks_Support() );
|
|
}
|
|
},
|
|
10,
|
|
1
|
|
);
|