如何使用woocommerce wordpress在运输方式中添加自定义字段

时间:2019-05-09 05:45:28

标签: wordpress woocommerce

如何使用woocommerce wordpress 在送货方式中添加自定义字段

请查看我的屏幕截图shipping method screenshot

2 个答案:

答案 0 :(得分:1)

请尝试使用此代码。

Committing new block , number=703437 txs=0 special-txs=0 uncles=0 elapsed=337.344µs,
Successfully sealed new block number=703437 hash=fd51a0…6aafb9

答案 1 :(得分:0)

如果有人正在寻找如何使用@Өлзийбат-Нансалцог 代码示例获取值。我能够以这种方式检索它:

//Get Shipping rate object
//$method->id is the ID of the shipping method. 
//In my case I used that in cart-shipping.php template
$WC_Shipping_Rate = new WC_Shipping_Rate($method->id); 

// Returned value is flat_rate:1
$shipping_rate_id = $WC_Shipping_Rate->get_id(); 

//Replacing : with underscore to have the id in format of flat_rate_1
$shipping_rate_id = str_replace(':', '_', $shipping_rate_id);

//Get the description field value
//Since the value is stored inside options table use get_option() method
get_option('woocommerce_'.$shipping_rate_id.'_settings')['shipping_extra_field_description']