2017-02-13 19 views
5

çıkış sayfasında 'ücretsiz gönderim' yöntemi için minimum sipariş miktarı alınıyor:
How to get minimum order amount for free shipping in woocommerceBu cevap kodu kullanmaya çalıştı vermedi gelmiş

Ama NULL sonucu döndüren ve ben bulamıyorum Şu ana kadar bu kodu düzeltmenin yolu.

Ödeme sayfasındaki doğru minimun sipariş miktarını nasıl edinebilirim?

Teşekkür

Sen alarak seçeneği almak gerekir
+0

Olası kopyalar (http://stackoverflow.com/questions/26582039/how-to-get-minimum-order-amount-for-free [WooCommerce serbest nakliye için minimum sipariş miktarı nasıl alınır] -hesaplama-in-woocommerce) –

+0

lütfen tekrar açıklamamı tekrar okuyun. Bunu beğendim (bağlantınız) ama NULL sonucunu döndürür. Ben böyle yapıyorum: $ selected_methods = WC() -> session-> get ('selected_shipping_methods'); \t \t $ selected_shipping = $ selected_methods [0]; ama seçilen yöntem Free Shipping ise min_amount nasıl alabilirim? – huykon225

+0

@LoicTheAztec soruyu veya açıklamayı değiştirmek zorunda olduğum anlamına mı geliyor? İstediğim her şey: Ödeme sayfasına geldiğimde ve bir nakliye yöntemini seçtiğimde Ücretsiz Kargo, ** bu yöntemin ** minimum miktarını almak istiyorum. Bana yardımcı olabilir misiniz ? – huykon225

cevap

4

bu cevabın kodu: How to get minimum order amount for free shipping in woocommerce
, WooCommerce sürüm 2 ile geçersiz'dur. 6+, ancak bu işlevsel yanıt için yardımcı oldu…

Bazı arama ve bazı denemeler yaptıktan sonra, belirli bir bölge için Ücretsiz Gönderim yönteminde ayarlanan minimum Sipariş miktarını alma yolunu buldum (Bölge):

// 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; 

Bingo: Burada

enter image description here

çalışma test kodu (açıklamalar içeride yorumlanmıştır) 'dir! anladın.

+1

yardım et çok yardımcı ol. Onu yeni buldum ve aynı sonuca vardım. tekrar teşekkürler ! – huykon225

+1

coşkunuz için teşekkür ederiz. iyi günler;)) – huykon225

+0

evet efendim. Bunu aklımda yapacağım. teşekkürler – huykon225

0

ardından

get_option('woocommerce_free_shipping_1_settings'); 

Ve unserialize yaparak verileri

maybe_unserialize(); 
+0

cevabınıza teşekkür ederiz. benim db çok fazla ** woocommerce_free_shipping_x_settings ** (x: 9-> 19 ile). Ben ödeme sayfasında min miktarı Ücretsiz Nakliye yöntemi olsun istiyorum. soruyu anladın mı ? lütfen bana – huykon225

0

Belki birilerine yardımcı olacaktır. Yeni ücretsiz gönderim nesnesi oluşturabilir ve bundan min_amount alabilirsiniz. Bence @LoicTheAztec cevabından daha basit.

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

woocommerce 2.6 veya heigher ile çalışmıyor. cevabınızı göndermeden önce kontrol edin? – huykon225

İlgili konular