2017-04-22 4 views
0

안녕하십니까, 내 상점에서 현금으로 지불 (COD) 결제 방법의 간단한 복사본을 만들고 배달시 쿠폰 이름으로 바꾸고 싶습니다. 구현 방법은 무엇입니까?WooCommerce 용 간단한 오프라인 지불 게이트웨이를 만드는 방법은 무엇입니까?

이 코드를 시도 까지

하지만 WC 설정 페이지에 오류 500을 보여줍니다

<?php 
/** 
* Plugin Name: My New WooCommerce Gateway 
* Plugin URI: 
* Description: WooCommerce gateway to .... 
* Author: ..... 
* Version: 1.0 
* Author URI: https://example.org/ 
* Text Domain: woocommerce-my-gateway 
* Domain Path: /languages/ 
*/ 

add_action('plugins_loaded', 'init_my_gateway_class'); 

function init_my_gateway_class() { 
    if (!class_exists('WooCommerce')) return; 
    class WC_Gateway_COD_Renamed extends WC_Payment_Gateway { 
    } 
} 

function add_my_gateway_class($methods) { 
    $methods[] = 'WC_Gateway_my_gateway'; 
    return $methods; 
} 
add_filter('woocommerce_payment_gateways', 'add_my_gateway_class'); 

function my_load_textdomain(){ 
    load_plugin_textdomain('woocommerce-my-gateway', false, dirname(plugin_dir_path(__FILE__) . '/languages/')); 
} 
add_action('plugins_loaded', 'my_load_textdomain'); 
WooCommerce 플러그인에서

Source of code

+0

질문에 추가됨 – Darklez

+0

WooCommerce 설정 페이지에 오류 500이 표시됩니다. – Darklez

+0

'WC_Gateway_my_gateway' 클래스가 존재하지 않습니다. – helgatheviking

답변

1

, 당신은 관리자 섹션에서 지불 게이트웨이 COD를 활성화 할 수 있습니다

관리자 >> WooCommerce >> 설정 >> 결제 >> 대금 상환.

대금 결제 활성화 옵션을 선택하십시오.

오프라인 결제 게이트웨이 만들기에 대한 링크를 참조하십시오. 주 플러그인 파일에서

How to Create A WooCommerce Payment gateway

+0

고마워요.)하지만 문제는 대금 상환과 동일한 대금 결제 방법과 새로운 결제 방법이 필요하지만 다른 이름 (배송시 쿠폰)이 필요하다는 것입니다. 즉, 2 가지 오프라인 지불 방법이 필요합니다. – Darklez

+0

내 대답을 확인,뿐만 아니라 업데이 트되었습니다. – ashish

0

당신은 클래스를 포함하고 동시에 게이트웨이를 필터링 할 수 있습니다

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 클래스를 확장합니다.