2017-07-18 24 views
6

में कस्टम वर्किंग शिपिंग विधि को जोड़ने के लिए मैंने सफलतापूर्वक एक नई शिपिंग विधि बनाई है और इसे शिपिंग क्षेत्र के लिए समर्थन दिया है। हालांकि जब मैं इसे ज़ोन में जोड़ने के लिए ड्रॉपडाउन से विधि का चयन करने के लिए आता हूं तो यह 'चयनित विधियों की सूची' में प्रकट नहीं होता है।WooCommerce 3

मैं प्रदर्शित करने के लिए एक screencast gif दर्ज की गई:

screencast gif

मैं के लिए मुझे के जीवन क्यों यह काम नहीं कर रहा को समझ नहीं सकता। यह ठीक काम करता है अगर मैं मानक विधियों में से एक का चयन करता हूं (Screencast GIF)

कोई भी जानता है कि यहां क्या हो रहा है और इसे कैसे कामयाबी है?

कोड यह रहा है कि मैं from this official thread: Shipping Method API है:

if (in_array('woocommerce/woocommerce.php', apply_filters('active_plugins', get_option('active_plugins')))) { 

    function request_a_shipping_quote_init() { 
     if (! class_exists('WC_Request_Shipping_Quote_Method')) { 
      class WC_Request_Shipping_Quote_Method extends WC_Shipping_Method { 
       /** 
       * Constructor for your shipping class 
       * 
       * @access public 
       * @return void 
       */ 
       public function __construct() { 
        $this->id     = 'request_a_shipping_quote'; // Id for your shipping method. Should be uunique. 
        $this->method_title  = __('Request a Shipping Quote'); // Title shown in admin 
        $this->method_description = __('Shipping method to be used where the exact shipping amount needs to be quoted'); // Description shown in admin 

        $this->title = "Request a Shipping Quote"; // This can be added as an setting but for this example its forced. 

        $this->supports = array(
         'shipping-zones' 
        ); 

        $this->init(); 
       } 

       /** 
       * Init your settings 
       * 
       * @access public 
       * @return void 
       */ 
       function init() { 
        // Load the settings API 
        $this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings 
        $this->init_settings(); // This is part of the settings API. Loads settings you previously init. 

        // Save settings in admin if you have any defined 
        add_action('woocommerce_update_options_shipping_' . $this->id, array($this, 'process_admin_options')); 
       } 

       function init_form_fields() { 

        $this->form_fields = array(

         'enabled' => array(
          'title'  => __('Enable', 'dc_raq'), 
          'type'  => 'checkbox', 
          'description' => __('Enable this shipping method.', 'dc_raq'), 
          'default'  => 'yes' 
         ), 

         'title' => array(
          'title'  => __('Title', 'dc_raq'), 
          'type'  => 'text', 
          'description' => __('Title to be displayed on site', 'dc_raq'), 
          'default'  => __('Request a Quote', 'dc_raq') 
         ), 

        ); 

       } 

       /** 
       * calculate_shipping function. 
       * 
       * @access public 
       * 
       * @param mixed $package 
       * 
       * @return void 
       */ 

       public function calculate_shipping($packages = array()) { 
        $rate = array(
         'id'  => $this->id, 
         'label' => $this->title, 
         'cost'  => '0.00', 
         'calc_tax' => 'per_item' 
        ); 

        // Register the rate 
        $this->add_rate($rate); 
       } 
      } 
     } 
    } 

    add_action('woocommerce_shipping_init', 'request_a_shipping_quote_init'); 

    function request_shipping_quote_shipping_method($methods) { 
     $methods['request_shipping_quote_shipping_method'] = 'WC_Request_Shipping_Quote_Method'; 

     return $methods; 
    } 

    add_filter('woocommerce_shipping_methods', 'request_shipping_quote_shipping_method'); 
} 
+0

यह woocommerce में 3 + अब और काम नहीं कर रहा है, इस संयुक्त राष्ट्र को देखने के समर्थन धागा उत्तर दिया: //wordpress.org/support/topic/official-custom-shipping-class-doesnt-work-anymore-shipping-method-api/ – LoicTheAztec

+0

** WC_Shipping_Method 'calculate_shipping()' कोर विधि ** के साथ कोई संघर्ष है और वह जो आपके कोड प्लगइन में परिभाषित किया गया है ... यही वह बिंदु है जिसे हल करने की आवश्यकता है ईडी। क्योंकि ** यह त्रुटि फेंक दी गई है **: * सख्त मानकों: WC_Request_Shipping_Quote_Method :: गणना_shipping() की घोषणा WC_Shipping_Method :: गणना_शिपिंग ($ पैकेज = ऐरे) /www/wp-content/plugins/request_shipping_quote_method.php पर संगत होनी चाहिए लाइन 18 * – LoicTheAztec

+0

@LoicTheAztec इस के साथ कोई सफलता? – omukiguy

उत्तर

2

"woocommerce_shipping_methods" पर विधि कुंजी से मेल खाना चाहिए ई शिपिंग विधि आईडी

आपके मामले में: आप

function request_shipping_quote_shipping_method($methods) { 
    $methods['request_shipping_quote_shipping_method'] = 'WC_Request_Shipping_Quote_Method'; 

    return $methods; 
} 

add_filter('woocommerce_shipping_methods', 'request_shipping_quote_shipping_method'); 

करने के लिए बदलना चाहिए: https:

function request_shipping_quote_shipping_method($methods) { 
    $methods['request_a_shipping_quote'] = 'WC_Request_Shipping_Quote_Method'; 

    return $methods; 
} 

add_filter('woocommerce_shipping_methods', 'request_shipping_quote_shipping_method'); 
+0

केवल इस जवाब को देखा - यह तय किया गया है! उत्तर देने के लिए बहुत बहुत धन्यवाद, बहुत सराहना की – jhob101

3

बदलें इस लाइन

public function calculate_shipping($package) { 

इस लाइन

सार्वजनिक समारोह calculate_shipping ($ पैकेज = सरणी()) {

को
+0

इसके लिए धन्यवाद। मैंने उस कोड को लागू किया लेकिन यह अभी भी काम नहीं करता है। साइट वर्तमान में रिमोट है इसलिए मैं नहीं देख सकता कि कौन सी त्रुटियां फेंक दी गई हैं, यह स्थानीय रूप से काम कर रही है और देखें कि क्या मैं कोई त्रुटि देख सकता हूं। – jhob101

+0

तो जब मैं '$ पैकेज = सरणी() को जोड़ता हूं तो अब कोई त्रुटि नहीं फेंकती है लेकिन व्यवहार वही रहता है - शिपिंग विधि शिपिंग विधियों की सूची में नहीं जोड़ा जाता है। – jhob101

+0

आपको क्या त्रुटि मिल रही है? bcoz अब आपको यह जांचना है कि आपने अपने फ़ंक्शन के अंदर पैकेज कैसे प्रबंधित किए हैं, bcoz अब यह संकुलों की सरणी है – Alice