Woocomerce自定义付款方式将数据重定向到外部网站
我是WP的新手 我正在WC中构建付款方式,并且已经构建了在结帐时可见的基本插件。现在,我这个插件要发送产品ID或CART ID(如果有类似的话),
我想在应用程序(网站)上检索数据的
购物车价格,我也想将确认数据发送回WooCommerce。所有交易都必须在我的外部网站上发生。我不知道将使用什么挂钩来执行整个功能围栏
add_filter( 'woocommerce_payment_gateways', 'add_your_gateway_class' );
function add_your_gateway_class( $methods ) {
$methods[] = 'WC_Custom_PG';
return $methods;
}
add_action( 'plugins_loaded', 'init_wc_custom_payment_gateway' );
function init_wc_custom_payment_gateway(){
class WC_Custom_PG extends WC_Payment_Gateway {
function __construct(){
$this->id = 'wc_custom_pg';
$this->method_title = 'Custom Payment Gateway';
$this->title = 'Custom Payment Gateway';
$this->has_fields = true;
$this->method_description = 'Your description of the payment gateway';
$this->init_form_fields();
$this->init_settings();
$this->enabled = $this->get_option('enabled');
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option('description');
//process settings with parent method
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
public function init_form_fields(){
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable Custom Payment Gateway',
'default' => 'yes'
),
'title' => array(
'title' => 'Method Title',
'type' => 'text',
'description' => 'This controls the payment method title',
'default' => 'Custom Payment Gatwaye',
'desc_tip' => true,
),
'description' => array(
'title' => 'Customer Message',
'type' => 'textarea',
'css' => 'width:500px;',
'default' => 'Your Payment Gateway Description',
'description' => 'The message which you want it to appear to the customer in the checkout page.',
)
);
}
//this function lets you add fields that can collect payment information in the checkout page like card details and pass it on to your payment gateway API through the process_payment function defined above.
public function payment_fields(){
?>
<fieldset>
<p class="form-row form-row-wide">
<?php echo esc_attr($this->description); ?>
</p>
<div class="clear"></div>
</fieldset>
<?php
}
}
}
I'm totally new to WP
I am building a payment method in WC and I have built the basic plugin that is visible on checkout. Now I this plugin to send product id or cart id(if there is something like that), cart price
I want to retrieve the data on my application(website)
I also want to send confirmation data back to Woocommerce. All the transaction must happen in my external website. I have no idea what hooks will be used to perform the whole functionailty
add_filter( 'woocommerce_payment_gateways', 'add_your_gateway_class' );
function add_your_gateway_class( $methods ) {
$methods[] = 'WC_Custom_PG';
return $methods;
}
add_action( 'plugins_loaded', 'init_wc_custom_payment_gateway' );
function init_wc_custom_payment_gateway(){
class WC_Custom_PG extends WC_Payment_Gateway {
function __construct(){
$this->id = 'wc_custom_pg';
$this->method_title = 'Custom Payment Gateway';
$this->title = 'Custom Payment Gateway';
$this->has_fields = true;
$this->method_description = 'Your description of the payment gateway';
$this->init_form_fields();
$this->init_settings();
$this->enabled = $this->get_option('enabled');
$this->title = $this->get_option( 'title' );
$this->description = $this->get_option('description');
//process settings with parent method
add_action( 'woocommerce_update_options_payment_gateways_' . $this->id, array( $this, 'process_admin_options' ) );
}
public function init_form_fields(){
$this->form_fields = array(
'enabled' => array(
'title' => 'Enable/Disable',
'type' => 'checkbox',
'label' => 'Enable Custom Payment Gateway',
'default' => 'yes'
),
'title' => array(
'title' => 'Method Title',
'type' => 'text',
'description' => 'This controls the payment method title',
'default' => 'Custom Payment Gatwaye',
'desc_tip' => true,
),
'description' => array(
'title' => 'Customer Message',
'type' => 'textarea',
'css' => 'width:500px;',
'default' => 'Your Payment Gateway Description',
'description' => 'The message which you want it to appear to the customer in the checkout page.',
)
);
}
//this function lets you add fields that can collect payment information in the checkout page like card details and pass it on to your payment gateway API through the process_payment function defined above.
public function payment_fields(){
?>
<fieldset>
<p class="form-row form-row-wide">
<?php echo esc_attr($this->description); ?>
</p>
<div class="clear"></div>
</fieldset>
<?php
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论