This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathalipay.php
80 lines (68 loc) · 2.36 KB
/
alipay.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/*
* Plugin Name: Alipay For WooCommerce
* Plugin URI: http://www.codingpet.com
* Description: Integrate the Chinese Alipay payment gateway with Woocommerce. Alipay is one of the most widely used payment method in China.
* Version: 1.3.4
* Author: CodingPet
* Author URI: http://www.codingpet.com
* Requires at least: 3.9
* Tested up to: 4.0
*
* Text Domain: alipay
* Domain Path: /lang/
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
function wc_alipay_gateway_init() {
if( !class_exists('WC_Payment_Gateway') ) return;
load_plugin_textdomain( 'alipay', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
require_once( plugin_basename( 'class-wc-alipay.php' ) );
add_filter('woocommerce_payment_gateways', 'woocommerce_alipay_add_gateway' );
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'wc_alipay_plugin_edit_link' );
}
add_action( 'plugins_loaded', 'wc_alipay_gateway_init' );
/**
* Add the gateway to WooCommerce
*
* @access public
* @param array $methods
* @package WooCommerce/Classes/Payment
* @return array
*/
function woocommerce_alipay_add_gateway( $methods ) {
$methods[] = 'WC_Alipay';
return $methods;
}
/**
* Display Alipay Trade No. for customer
*
*
* The function is put here because the alipay class
* is not called on order-received page
*
* @param array $total_rows
* @param mixed $order
* @return array
*/
function wc_alipay_display_order_meta_for_customer( $total_rows, $order ){
$trade_no = get_post_meta( $order->id, 'Alipay Trade No.', true );
if( !empty( $trade_no ) ){
$new_row['alipay_trade_no'] = array(
'label' => __( 'Alipay Trade No.:', 'alipay' ),
'value' => $trade_no
);
// Insert $new_row after shipping field
$total_rows = array_merge( array_splice( $total_rows,0,2), $new_row, $total_rows );
}
return $total_rows;
}
add_filter( 'woocommerce_get_order_item_totals', 'wc_alipay_display_order_meta_for_customer', 10, 2 );
function wc_alipay_plugin_edit_link( $links ){
return array_merge(
array(
'settings' => '<a href="' . admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=wc_alipay') . '">'.__( 'Settings', 'alipay' ).'</a>'
),
$links
);
}
?>