1

WooCommerce への配送方法アドオンを作成しました: http://pastebin.com/SCsbDnnn

ただし、それは機能せず、次の出力が得られます: PHP Fatal error:

 Class 'WC_Shipping_Method' not found in class-wc-shipping-per-product.php, on line 44.

このクラスが見つからないのはなぜですか? 確認のために2つのファイルも含めましたが、うまくいきません:

include ('/woocommerce/woocommerce.php');

include_once( 'classes/abstracts/abstract-wc-shipping-method.php' );

そして、この他の質問を確認しましたが、私の質問は異なる可能性があるため、新しい質問を追加しました: WooCommerce Extending WC_Shipping_Method error: Class 'WC_Shipping_Method' not found

4

4 に答える 4

3

たぶん私は誤解していますが:

プラグインのディレクトリ名は次のとおりclass-wc-shipping-per-productですplugins

したがって、 (ディレクトリ内にある)を含めるwoocommerce.phpには、1つのディレクトリを作成して次のようにする必要があります。abstract-wc-shipping-method.phpplugins/woocommerce

ファイル: wp-content/plugins/class-wc-shipping-per-product/class-wc-s‌hipping-per-product.php

include_once('../woocommerce/woocommerce.php');
include_once('../woocommerce/classes/abstracts/abstract-wc-shipping-method.php');
于 2013-09-09T09:22:52.553 に答える
1

私も最近これに苦労しました.Web上のさまざまなスニペットは非常に誤解を招くものです. これは私がこれまでに得たものであり、うまくいくようです...

add_action('woocommerce_shipping_init', 'yourprefix_woocommerce_init_shipping_rate');
add_filter('woocommerce_shipping_methods', array('WC_Shipping_XXX_Custom_Rate', 'add_shipping_method'));

function yourprefix_woocommerce_init_shipping_rate()
{

    class WC_Shipping_XXX_Custom_Rate extends WC_Shipping_Method
    {

        static function add_shipping_method($methods)
        {
            $methods[] = 'WC_Shipping_XXX_Custom_Rate';
            return $methods;
        }

        function __construct()
        {
            $this->id = 'yourprefix_custom_shipping';
            $this->method_title = __('yourprefix Custom Shipping', 'woocommerce');
            $this->title = "yourprefix CUSTOM SHIPPING TITLE";  // Displays on the main shipping page
            $this->enabled = true;
            $this->init();
        }

        function init()
        {
            $this->init_settings();
        }

        function is_available($package)
        {
            if ($this->enabled === "no")
                return false;
            return apply_filters('woocommerce_shipping_' . $this->id . '_is_available', true);
        }
于 2013-09-23T23:17:53.673 に答える