我需要帮助在woocommerce 3+版本中生成新的送货方式。新字段的名称是“Nextday delivery”。与平率一样,它也需要在方法中存在,但它没有显示在下拉选择字段中。
以下是我试过的代码。但它不适合我。
function request_a_shipping_quote_init() {
if ( ! class_exists( 'WC_Request_Shipping_Quote_Method' ) ) {
class WC_Request_Shipping_Quote_Method extends WC_Shipping_Method {
public function __construct() {
$this->id = 'request_a_shipping_quote'; // Id for your shipping method. Should be uunique.
$this->method_title = __( 'Request a Shipping Quote' ); // Title shown in admin
$this->method_description = __( 'Shipping method to be used where the exact shipping amount needs to be quoted' ); // Description shown in admin
$this->title = "Request a Shipping Quote"; // This can be added as an setting but for this example its forced.
$this->supports = array(
'shipping-zones'
);
$this->init();
}
function init() {
$this->init_form_fields(); // This is part of the settings API. Override the method to add your own settings
$this->init_settings(); // This is part of the settings API. Loads settings you previously init.
add_action( 'woocommerce_update_options_shipping_' . $this->id, array( $this, 'process_admin_options' ) );
}
function init_form_fields() {
$this->form_fields = array(
'enabled' => array(
'title' => __( 'Enable', 'dc_raq' ),
'type' => 'checkbox',
'description' => __( 'Enable this shipping method.', 'dc_raq' ),
'default' => 'yes'
),
'title' => array(
'title' => __( 'Title', 'dc_raq' ),
'type' => 'text',
'description' => __( 'Title to be displayed on site', 'dc_raq' ),
'default' => __( 'Request a Quote', 'dc_raq' )
),
);
}
public function calculate_shipping( $packages = array() ) {
$rate = array(
'id' => $this->id,
'label' => $this->title,
'cost' => '0.00',
'calc_tax' => 'per_item'
);
$this->add_rate( $rate );
}
}
}
}
add_action( 'woocommerce_shipping_init', 'request_a_shipping_quote_init' );
function request_shipping_quote_shipping_method( $methods ) {
$methods['request_shipping_quote_shipping_method'] = 'WC_Request_Shipping_Quote_Method';
return $methods;
}
add_filter( 'woocommerce_shipping_methods', 'request_shipping_quote_shipping_method' );
我需要它像平板免费送货等进入下拉菜单,但它没有进入下拉列表。
答案 0 :(得分:4)
有些遗失的东西和其他不必要的东西。使其正常工作的正确方法是:
df %>%
arrange(forcats::fct_relevel(col2, order_vector))
# col1 col2 col3
# 1 3 CHL spec1
# 2 8 CHL spec2
# 3 4 GEN spec1
# 4 9 GEN spec2
# 5 1 COL spec1
# 6 6 COL spec2
# 7 2 CIP spec1
# 8 7 CIP spec2
# 9 5 TMP spec1
# 10 10 TMP spec2
代码进入活动子主题(活动主题)的function.php文件。
经过测试和工作。
此处的送货方式选择器现在显示此"请求送货海岸"方法:
选择并添加后,这次创建了它:
如果你编辑它: