Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WooCommerce自定义装运方法出现在错误的位置_Php_Wordpress_Woocommerce - Fatal编程技术网

Php WooCommerce自定义装运方法出现在错误的位置

Php WooCommerce自定义装运方法出现在错误的位置,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我添加了一个WordPress插件,该插件带有从复制的自定义传送方法–我唯一真正做的更改是为calculate\u shipping的$package参数添加一个默认的array()值,以消除错误WC\u shipping\u方法的声明::calculate\u shipping()应与WC_Shipping_Method::calculate_Shipping($package=Array)兼容 奇怪的是,我的新方法出现在配送设置的顶部。我希望在我将方法添加到配送区时,它会出现在可用方法的下拉

我添加了一个WordPress插件,该插件带有从复制的自定义传送方法–我唯一真正做的更改是为
calculate\u shipping
$package
参数添加一个默认的
array()
值,以消除错误
WC\u shipping\u方法的声明::calculate\u shipping()应与WC_Shipping_Method::calculate_Shipping($package=Array)
兼容

奇怪的是,我的新方法出现在配送设置的顶部。我希望在我将方法添加到配送区时,它会出现在可用方法的下拉列表中。有人能看出我犯了什么错误吗

我已经检查了
woocommerce\u shipping\u methods
过滤器中的键是否与我的类的
$this->id
匹配,这是中的问题所在


未设置您创建的
WC\u-Your\u-Shipping\u方法
类的
$supports
属性。这就是为什么您在WooCommerce后端的添加配送方法部分中看不到它的原因

以下是WooCommerce的摘要
WC\u Shipping\u方法
class的摘录:

/**
 * Features this method supports. Possible features used by core:
 * - shipping-zones Shipping zone functionality + instances
 * - instance-settings Instance settings screens.
 * - settings Non-instance settings screens. Enabled by default for BW compatibility with methods before instances existed.
 * - instance-settings-modal Allows the instance settings to be loaded within a modal in the zones UI.
 *
 * @var array
 */
public $supports = array( 'settings' );
因此,要查看新的shipping方法,您需要更改类构造函数,如下所示:

public function __construct() {
    $this->id                 = 'your_shipping_method'; // Id for your shipping method. Should be uunique.
    $this->method_title       = __( 'Your Shipping Method' );  // Title shown in admin
    $this->method_description = __( 'Description of your shipping method' ); // Description shown in admin
    // set supported features
    $this->supports           = array(
        'shipping-zones',
        'instance-settings',
    );
    $this->enabled            = "yes"; // This can be added as an setting but for this example its forced enabled
    $this->title              = "My Shipping Method"; // This can be added as an setting but for this example its forced.

    $this->init();
}
该代码已经过测试,可以正常工作

有用的链接


啊,我明白了!非常感谢@vincenzo di gaetano,成功了!