嗨,我正在使用Woocommerce 3.5.1自定义运输插件,该插件具有2种具有常用设置的运输方法。为此,我创建了一个父类和2个子类,但无法检索子类的设置。有一种创建全局设置选项的方法吗?
class WC_XXX extends WC_Shipping_Method {
public function __construct($instance_id = 0) {
$this->instance_id = absint( $instance_id );
if (!$this->id) {
$this->id = "xxx";
$this->title = __("XXX","woocommerce-xxx");
$this->method_title = __("XXX","woocommerce-xxx");
$this->method_description = __("XXX","woocommerce-xxx");
}
// Options
$this->init_form_fields();
$this->init_settings();
$this->enabled = $this->get_option("enabled");
$this->token = $this->get_option("token");
add_action("woocommerce_update_options_shipping_xxx", array($this, "process_admin_options"));
}
function init_form_fields() {
$this->form_fields = array(
"enabled" => array(
"title" => __("Enabled","woocommerce-xxx"),
"type" => "checkbox",
"description" => __("sdsds.","woocommerce-xxx" ),
"default" => "yes"
),
"token" => array(
"title" => __("Token","woocommerce-xxx"),
"type" => "text",
"description" => __("Token","woocommerce-xxx"),
"default" => __("91e217f3-34a9","woocommerce-xxx")
)
);
}
}
class WC_XXX_Lowcost extends WC_XXX {
public function __construct( $instance_id = 0 ) {
$this->id = "xxx-lowcost";
$this->title = __("Low Cost Shipping","woocommerce-xxx");
$this->method_title = __("Low Cost Shipping","woocommerce-xxx");
$this->method_description = __("Low Cost Shipping","woocommerce-xxx");
$this->supports = array("shipping-zones");
parent::__construct( $instance_id );
}
}
class WC_XXX_Express extends WC_XXX {
public function __construct( $instance_id = 0 ) {
$this->id = "xxx-express";
$this->title = __("Express Shipping","woocommerce-xxx");
$this->method_title = __("Express Shipping","woocommerce-xxx");
$this->method_description = __("Express Shipping Shipping","woocommerce-xxx");
$this->supports = array("shipping-zones");
parent::__construct( $instance_id );
}
}
function add_xxx_methods( $methods ) {
$methods["xxx-lowcost"] = "WC_XXX_Lowcost";
$methods["xxx-express"] = "WC_XXX_Express";
$methods["xxx"] = "WC_XXX";
return $methods;
}
add_filter("woocommerce_shipping_methods","add_xxx_methods");