标题很好地解释了这一点。我试图通过扩展这个类来添加一个新的运输方法(基于成本的运输)。这是插件的正文(其余部分在注释中,包含插件信息):
class WC_Cost_Based extends WC_Shipping_Method {
function __construct() {
$this->id = 'cost-based';
$this->method_title = __('Cost-Based', 'woocommerce');
}
function calculate_shipping() {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => '10.99',
'calc_tax' => 'per_item'
);
// Register the rate
$this->add_rate( $rate );
}
}
function add_cost_based_method( $methods ) {
$methods[] = 'WC_Cost_Based';
return $methods;
}
add_filter('woocommerce_shipping_methods', 'add_cost_based_method');文件保存在.../wp-content/cost-based中
你知道为什么会弹出这个错误吗?
发布于 2013-02-28 12:25:22
我只是在尝试遵循woocommerce的说明/教程时遇到了同样的问题。他们似乎遗漏了几件事。
首先,为了解决你的问题,我发现我需要在我的插件类的顶部包含woocommerce.php。这将使新的运输类能够访问它需要扩展的WC_Shipping_Method。可能有一种更优雅的方式,只包含依赖类。对我来说,include看起来是这样的:
include ('/woocommerce/woocommerce.php');其次,我发现我还必须在__construct()方法中设置至少两个属性。它们是:
$this->title = "YOUR TITLE"; // Displays on the main shipping page
$this->enabled = true;第三,我还需要(至少):
function is_available( $package ) {
if ( $this->enabled == "no" ) return false;
return apply_filters( 'woocommerce_shipping_' . $this->id . '_is_available', true );
}希望它能帮上忙!
西蒙
发布于 2018-12-06 15:24:14
复制php文件中的所有内容,并替换位于- wp-content/plugins/woocommerce/includes/abstracts/中的文件-abstract-wc-shipping-method.php
https://stackoverflow.com/questions/14972184
复制相似问题