我刚刚创建了一个自定义的 Woocommerce 运输方式,ID 为custom_shipping. 该选项现在出现在 Woocommerce -> 设置 -> 运输管理页面上。
我想根据用户的凭据动态设置运输方式。默认方法是flat_rate现在。
问题:
如何custom_shipping为满足要求的用户在整个会话期间设置送货方式?
尝试:
$chosen_methods = $woocommerce->session->set('chosen_shipping_methods', array('purolator_shipping');
Run Code Online (Sandbox Code Playgroud)
这在我的cart页面上正确设置了会话变量 'chosen_shipping_methods' ,但在移动到 时checkout,会话将返回到使用flat_rate运输方式。
必须有一个钩子或过滤器,我可以插入它以在创建购物车会话或其他事情时更改运输方式。(当用户第一次将东西添加到购物车时)。
理想情况下,我想在加载其他任何东西之前设置新的运输方式,以便他们的购物车和结帐摘要中的运输方式看起来正确。
指导表示赞赏。
我正在尝试向我的 Woocommerce 套件添加新的运输方式。
基本上,我尝试根据用户角色对订单应用两种不同的运费。我使用统一费率作为其中之一,但需要定制一个。
我已经尝试使用Shipping api创建一个新类,但似乎没有显示任何内容。
<?php namespace MySite;
use WC_Shipping_Method;
function your_shipping_method_init() {
if ( ! class_exists( 'CustomShipping' ) ) {
class CustomShipping extends WC_Shipping_Method {
/**
* Constructor for your shipping class
*
* @access public
* @return void
*/
public function __construct() {
$this->id = 'your_shipping_method'; // Id for your shipping method. Should be uunique.
$this->method_title = __( 'Your Shipping Method' ); // Title shown in admin
$this->method_description = __( 'Description of your shipping method' …Run Code Online (Sandbox Code Playgroud)