Disable shipping method on Dokan if the store is closed

Viewed 529

Is there any way to use this code for disabling a specific shipping method? For example, if I want to use a "flat rate" method, and if the store closes, I want this method not to appear.

I tried to replace the is_purchasable hook with woocommerce_load_shipping_methods with instance id "6", but that didn't work.

Below is the code that is working for disabling a purchase, but not the shipping method.

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;

}

1 Answers

You can try this code in the child theme's functions.php file.

remove_filter( 'woocommerce_cart_shipping_packages', 
'dokan_custom_split_shipping_packages' );

Dokan sipping will be disabled by using this code. Admin will manage shipping from the backend (WooCommerce Shipping)

Related