私は今、この問題を解決しました。私の解決策は間違いなくすべての人に適しているわけではありませんが、誰かを助けるかもしれません.
私は woocommerce にこのテーブルレート配送プラグインを使用しています: http://codecanyon.net/item/table-rate-shipping-for-woocommerce/3796656?WT (これが機能する方法を複製したい場合)
この質問の答えにお世話になっています:配送オプションを隠す Woocommerce
コードは基本的にそれをコピーしたものですが、商品の在庫数を確認するように設定されています。
このコードは、バックオーダーが許可されているかどうかを考慮しません。文字通り、在庫数が > 0 で、カート数 <= 在庫数であるかどうかをチェックします。基本的に商品が倉庫にある場合はチェックアウト時に翌日発送、ない場合は商品を削除して通常配送のみとなります。
/* !Hide Shipping Options Woocommerce */
add_filter( 'woocommerce_available_shipping_methods', 'hide_shipping_based_on_quantity' , 10, 1 );
function check_cart_for_oos() {
// load the contents of the cart into an array.
global $woocommerce;
$found = false;
foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $values ) {
$_product = $values['data'];
$_product_quantity = $_product->get_stock_quantity();
$_cart_quantity = $values['quantity'];
if (($_product_quantity <= 0) || ($_cart_quantity > $_product_quantity)) {
$found = true;
break;
}
}
return $found;
}
function hide_shipping_based_on_quantity( $available_methods ) {
// use the function check_cart_for_oos() to check the cart for products with 0 stock.
if ( check_cart_for_oos() ) {
// remove the rate you want
unset( $available_methods['table_rate_shipping_next-day'] ); // Replace "table_rate_shipping_next-day" with "table_rate_shipping_your-identifier".
}
// return the available methods without the one you unset.
return $available_methods;
}