首页 > 解决方案 > 如果商店关闭,请在 Dokan 上禁用送货方式

问题描述

有什么方法可以使用此代码禁用特定的运输方式?例如,如果我想使用“统一费率”方法,并且如果商店关门,我希望这种方法不出现。

我试图用实例 id 为“6”的 woocommerce_load_shipping_methods 替换 is_purchasable 挂钩,但这没有用。

以下是用于禁用购买的代码,但不是运输方式。

add_filter( 'woocommerce_is_purchasable', 'prefix_woocommerce_is_purchasable', 10, 2 );
function prefix_woocommerce_is_purchasable( $is_purchasable, $product ) {

// Get the store id.
$store_id = get_post_field( 'post_author', $product->get_id() );

// Get the store info.
$store_info = dokan_get_store_info( $store_id );

// Get the store time enabled or not.
$is_dokan_store_time_enabled = $store_info['dokan_store_time_enabled'];

// If the store time is enabled, check whether the store is open or not.
// Else the store is open.
if ( 'yes' === $is_dokan_store_time_enabled ) {
    $is_purchasable = dokan_is_store_open( $store_id );     
} else  {
    $is_purchasable = true;
}

return $is_purchasable;

}

标签: phpwordpresswoocommerceshippingdokan

解决方案


您可以在子主题的functions.php文件中尝试此代码。

remove_filter( 'woocommerce_cart_shipping_packages', 
'dokan_custom_split_shipping_packages' );

使用此代码将禁用 Dokan 啜饮。管理员将从后端管理运输(WooCommerce Shipping)


推荐阅读