1

テーブル レート配送プラグインを使用して 4 つの配送ゾーンを設定し、各ゾーンには標準配送オプションと翌日配送オプションがあります。

ストア内のすべての商品は 10 ~ 15 日以内に入手可能になりますが、多くの商品は在庫があり、翌日発送が可能です。カート内の商品のいずれかの在庫がない場合は、標準配送オプションのみを利用できます。

この同様の質問/回答がここに示されているように、「woocommerce_available_shipping_methods」フィルターを使用する必要があると確信しています:配送オプションを非表示にする Woocommerceですが、各カート項目の在庫レベルを確認する方法については完全にわかりません。

どんなポインタでも大歓迎です。

4

1 に答える 1

2

私は今、この問題を解決しました。私の解決策は間違いなくすべての人に適しているわけではありませんが、誰かを助けるかもしれません.

私は 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;
}
于 2013-11-12T10:29:01.000 に答える