2016-08-19 7 views
0

チェックアウトページでshipping_method_0_local_pickup_plusがチェックされている場合にのみ、woocommerceでdelivery_datetime_fieldチェックアウトフィールドを表示しようとしています。Woocommerce Checkoutフィールドを出荷方法に基づいて表示し、表示する際に必須フィールドにする

私は仮想製品のチェックアウトフィールドを隠すためにthis guideに基づいてその機能を構築しようとしています。

しかし、私は致命的なエラーが発生しています:チェックアウトページでサポートされていないオペランドタイプ。

add_filter('woocommerce_checkout_fields' , 'woo_remove_billing_checkout_fields'); 
function woo_remove_billing_checkout_fields($fields) { 
if ($chosen_methods[0] == 'shipping_method_0_local_pickup_plus'){ 
if(woo_cart_has_virtual_product() == true) { 
    unset($fields['billing']['delivery_datetime_field']); 
} 
return $fields; 
} 
if(count($products) == $virtual_products) 
$has_virtual_products = true; 
return $has_virtual_products; 
} 

誰にもこれに対応する方法はありますか?

私は誰もがそれを必要とする場合、ここで、ローカルピックアッププラスプラグインにはほとんどの編集を経てそれを行うことができた
+0

問題は、このラインであります... – LoicTheAztec

答えて

0

:唯一の問題は今、隠されたものの場合は、チェックアウトではないだろう、ということである

if (localPickupPlusOnly && ! $('#ship-to-different-address-checkbox').prop('checked')) { 
         // only local pickup plus is being used, hide the shipping address fields 
         $('#shiptobilling, #ship-to-different-address').hide(); 
         $('#delivery_datetime_field').show(); 
         $('#shiptobilling, #ship-to-different-address').parent().find('h3').hide(); 
         $('.shipping_address').hide(); 
        } else { 
         // some other shipping method is being used, show the shipping address fields 
         $('#shiptobilling, #ship-to-different-address').show(); 
         $('#delivery_datetime_field').hide(); 
         $('#shiptobilling, #ship-to-different-address').parent().find('h3').show(); 
         if (($('#shiptobilling input').length > 0 && ! $('#shiptobilling input').is(':checked')) || $('#ship-to-different-address input').is(':checked')) { 
          $('.shipping_address').show(); 
         } 
        } 

delivery_datetime_fieldが必須フィールドとして有効になっています。チェックアウト時にローカルピックアップが選択された場合にのみ、フィールドが必要になります。

誰もが解決策を探している場合は、次の$ chosen_methods`が定義されていない{ ``と `IF($ chosen_methods [0] == 'shipping_method_0_local_pickup_plus'):

add_filter('woocommerce_checkout_fields', 'local_pickup_disable'); 
function local_pickup_disable($local_pickup) { 
    global $woocommerce; 
    $chosen_methods = WC()->session->get('chosen_shipping_methods'); 
    $chosen_shipping = $chosen_methods[0]; 

    if($chosen_shipping == 'local_pickup_plus') { 
/** 
* Process the local_pickup checkout 
*/ 
add_action('woocommerce_checkout_process', 'my_custom_checkout_local_pickup_process'); 

function my_custom_checkout_local_pickup_process() { 
    // Check if set, if its not set add an error. 
    if (! $_POST['delivery_datetime']) 
     wc_add_notice(__('Please let us know when you plan to pick up your order by selecting a collection date.'), 'error'); 
    else 
     /** 
* Update the order meta with Pick Up question 
**/ 
add_action('woocommerce_checkout_update_order_meta', 'my_pickup_field_update_order_meta', 10, 2); 
function my_pickup_field_update_order_meta($order_id, $posted) { 
    if ($_POST['delivery_datetime']) { 
     update_post_meta($order_id, '_e_deliverydate', esc_attr($_POST['delivery_datetime'])); 
    } 
} 
/** 
* Add the Pick Up custom fields to order emails 
**/ 
add_filter('woocommerce_email_order_meta_keys', 'my_pickup_checkout_field_order_meta_keys'); 
function my_pickup_checkout_field_order_meta_keys($keys) { 
    $label_name = __("Pick Up Date","delivery_datetime"); 
    $keys[$label_name] = "Pick Up Date"; 
    return $keys; 
} 

} 
+0

この解決法は機能しません。プラグインを直接編集する必要はありません。 – Ravimallya

関連する問題