WooCommerce扩展WC_Shipping_Method错误:未找到类"WC_Shipping_Method" [英] WooCommerce Extending WC_Shipping_Method error: Class 'WC_Shipping_Method' not found
本文介绍了WooCommerce扩展WC_Shipping_Method错误:未找到类"WC_Shipping_Method"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
标题说明得很好.我正在尝试通过扩展类来添加新的送货方式(基于费用的送货).这是插件主体(其余部分在注释中,包含插件信息):
The title explains it pretty well. I'm trying to add a new shipping method (cost-based shipping) by extending the class. Here is the plugin body (The rest is in comments and contains the plugin info):
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
The file is saved in .../wp-content/cost-based
知道为什么会弹出此错误吗?
Any idea why this error is popping up?
推荐答案
将所有内容复制到php文件中,并替换为- wp-content/plugins/woocommerce/includes/abstracts/
copy everything in the php file and replace in the file -abstract-wc-shipping-method.php found in- wp-content/plugins/woocommerce/includes/abstracts/
这篇关于WooCommerce扩展WC_Shipping_Method错误:未找到类"WC_Shipping_Method"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文