2017-02-13 8 views
5

チェックアウトページで「送料無料」メソッドの最小注文金額の取得:
How to get minimum order amount for free shipping in woocommerceは、私はこの答えからコードを使用しようとしなかったしている

しかし、それは、NULL結果を返すと私は見つけることができません今までこのコードを修正する方法。

どのように私は右を得ることができます最小注文金額チェックアウトページで?あなたは、取得することにより、オプションを取得

get_option('woocommerce_free_shipping_1_settings'); 

そして実行してデータをアンシリアライズする必要が

おかげ

+0

可能な重複(http://stackoverflow.com/questions/26582039/how-to-get-minimum-order-amount-for-free [woocommerceで送料無料のための最小注文量を取得する方法] wi-ocommerce) –

+0

私の説明をもう一度読んでください。私はそれを(あなたのリンク)好きですが、それはNULLの結果を返します。私は次のようにしています: $ selected_methods = WC() - >セッション - > get( 'selected_shipping_methods'); \t \t $ chosen_shipping = $ selected_methods [0]; 選択した方法が送料無料の場合、どのようにmin_amountを取得できますか? – huykon225

+0

@LoicTheAztecあなたは質問や説明を変更する必要があるという意味ですか? 私が欲しいもの全て:チェックアウトページに来て、配送方法を選択すると送料が無料になります。手伝って頂けますか ? – huykon225

答えて

4

この回答のコード:How to get minimum order amount for free shipping in woocommerce
は、WooCommerceバージョン2で廃止されたです。 6 +が、この機能的な答えに役立ちました...

検索といくつかの試行をした後、私は、特定のゾーンの送料無料の方法で設定されている最小注文量を得る方法を見つけました(地方):

// Here you get (as you already know) the used shipping method reference 
$chosen_methods = WC()->session->get('chosen_shipping_methods'); 

// Replacing inside the string ':' by '_' 
$option_value = str_replace(':', '_', $chosen_methods[0]); 

// We concatenate the string with additional sub-strings 
$option_value = 'woocommerce_'.$option_value.'_settings'; 

// Just a test => outputting the string to see what we get 
echo $option_value; echo '<br>'; 

// Now we can get the options values with that formatted string 
$free_shipping_settings = get_option($option_value); 

// Just for test => we output the (pre-formatted) array of values to check 
echo '<pre>'; print_r($free_shipping_settings); echo '</pre><br>'; 

// Here we get the value of the order min amount (Finally!) 
$order_min_amount = $free_shipping_settings['min_amount']; 

// We output the value (to check) 
echo 'Order min amount: '.$order_min_amount; 

ビンゴ:ここ

enter image description here

は作業テストコード(説明は内側コメントしている)です!あなたはそれを手に入れます。

+1

ありがとうございました。私はちょうどそれを見つけて、ここに同じ結果を出します。ありがとうございました ! – huykon225

+1

あなたの熱意に感謝します。良い一日を);)) – huykon225

+0

yes sire。私はそれを私の心の中でするつもりです。ありがとう – huykon225

0

maybe_unserialize(); 
+0

あなたの答えに感謝します。私のDBはあまりにも多くの** woocommerce_free_shipping_x_settings **(x:9 - > 19)です。私はチェックアウトページで最小量の送料無料の方法を取得したい。あなたはその質問を理解していますか?助けてください – huykon225

0

多分それは誰かを助けるでしょう。あなたは新しい送料無料のオブジェクトを作成し、そこからmin_amountを得ることができます。私はそれが@LoicTheAztec答えよりも簡単だと思います。

if (class_exists('WC_Shipping_Free_Shipping')) { 
    $free_shipping = new WC_Shipping_Free_Shipping(); 
    $min_amount = $free_shipping->min_amount; 
    echo $min_amount; 
} 
+0

それはwoocommerce 2.6またはheigherで動作していません。あなたの答えを送る前に確認してください? – huykon225

関連する問題