당신은 클래스를 포함하고 동시에 게이트웨이를 필터링 할 수 있습니다
function add_my_gateway_class($methods) {
include('class-wc-gateway-cod-renamed.php');
$methods[] = 'WC_Gateway_COD_Renamed';
return $methods;
}
add_filter('woocommerce_payment_gateways', 'add_my_gateway_class');
WooCommerce가 woocommerce_payment_gateways
으로이 방법이 활성화되어 있는지 확인하기 위해 실제 필요가 없습니다 만 WooCommerce가 실행 중인지 존재합니다.
다음라는 다른 파일에 class-wc-gateway-cod-renamed.php
당신은 당신의 클래스를 정의 할 수 있습니다 : 당신이 그것에서 메서드를 상속 만 사물의 이름으로해야 할 메소드를 오버라이드 (override) 할 수 있도록
class WC_Gateway_COD_Renamed extends WC_Gateway_COD {
/**
* Setup general properties for the gateway.
*/
protected function setup_properties() {
$this->id = 'coupon-on-delivery';
$this->icon = apply_filters('woocommerce_coupon-on-deliver_icon', '');
$this->method_title = __('Coupon on delivery', 'your-plugin');
$this->method_description = __('Have your customers pay with a coupon upon delivery.', 'your-plugin');
$this->has_fields = false;
}
/**
* Initialise Gateway Settings Form Fields.
*/
public function init_form_fields() {
$shipping_methods = array();
foreach (WC()->shipping()->load_shipping_methods() as $method) {
$shipping_methods[ $method->id ] = $method->get_method_title();
}
$this->form_fields = array(
'enabled' => array(
'title' => __('Enable/Disable', 'your-plugin'),
'label' => __('Enable coupon on delivery', 'your-plugin'),
'type' => 'checkbox',
'description' => '',
'default' => 'no',
),
'title' => array(
'title' => __('Title', 'your-plugin'),
'type' => 'text',
'description' => __('Payment method description that the customer will see on your checkout.', 'your-plugin'),
'default' => __('coupon on delivery', 'your-plugin'),
'desc_tip' => true,
),
'description' => array(
'title' => __('Description', 'your-plugin'),
'type' => 'textarea',
'description' => __('Payment method description that the customer will see on your website.', 'your-plugin'),
'default' => __('Pay with coupon upon delivery.', 'your-plugin'),
'desc_tip' => true,
),
'instructions' => array(
'title' => __('Instructions', 'your-plugin'),
'type' => 'textarea',
'description' => __('Instructions that will be added to the thank you page.', 'your-plugin'),
'default' => __('Pay with coupon upon delivery.', 'your-plugin'),
'desc_tip' => true,
),
'enable_for_methods' => array(
'title' => __('Enable for shipping methods', 'your-plugin'),
'type' => 'multiselect',
'class' => 'wc-enhanced-select',
'css' => 'width: 400px;',
'default' => '',
'description' => __('If coupon upon delivery is only available for certain methods, set it up here. Leave blank to enable for all methods.', 'your-plugin'),
'options' => $shipping_methods,
'desc_tip' => true,
'custom_attributes' => array(
'data-placeholder' => __('Select shipping methods', 'your-plugin'),
),
),
'enable_for_virtual' => array(
'title' => __('Accept for virtual orders', 'your-plugin'),
'label' => __('Accept coupon if the order is virtual', 'your-plugin'),
'type' => 'checkbox',
'default' => 'yes',
),
);
}
}
가 WC_Gateway_COD
클래스를 확장합니다.
질문에 추가됨 – Darklez
WooCommerce 설정 페이지에 오류 500이 표시됩니다. – Darklez
'WC_Gateway_my_gateway' 클래스가 존재하지 않습니다. – helgatheviking