حذف فیلد های غیر ضروری ثبت سفارش در ووکامرس

یوسف پور امینیان 1396-01-02 9 دقیقه مطالعه
2 دیدگاه

در این آموزش میخواهیم چگونگی حذف فیلد های غیر ضروری در فرم سفارش ووکامرس برای فایل های دانلود یا مجازی را شرح دهیم .

ابتدا باید به قسمت زیر مراجعه کنید :

ووکامرس >> پیکربندی > محصولات > محصولات دانلودی

از قسمت محدودیت های دسترسی ، تیک قسمت “دانلودها نیازمند ورود هستند” رو بردارید ، سپس ” دسترسی به محصولات دانلودشدنی بعد از پرداخت” رو بزنید .

بعد از اینکار میببایست وارد هاست خودتون بشید و کد زیر رو در فایل فانکشن function خود قرار بدید .

<?php      کدی که باید در بالا و ابتدای فایل function قرار بدید .



?>         کدی که باید در پایین و انتهای فایل function قرار بدید .

توجه : اگر در ابتدا و انتهای برگه فانکش شما کد های بالا بود کد زیر رو فقط در فایل function خود کپی کنید . در غیر اینصورت کد بالا را به اول و آخر برگه اضافه کنید .

add_filter( 'woocommerce_checkout_fields' , 'WooCommerce_EDD_Checkout' );
function WooCommerce_EDD_Checkout( $fields ) {
    
    global $woocommerce;
    $hasPhysicalProduct = false;
    
    if ( ! empty( $woocommerce->cart->cart_contents ) ) {
        
        $cart = $woocommerce->cart->get_cart();
        foreach ( $cart as $key => $values ) {

            $_product = get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );

            if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > 0 ) {
                
                if ($_product->virtual == 'no' && $_product->downloadable == 'no') {
                    $hasPhysicalProduct = true;
                    break;
                }
            }
        }
    }

    if ($hasPhysicalProduct == false) {
        //unset($fields['billing']['billing_last_name']);
        //unset($fields['billing']['billing_phone']);
        unset($fields['billing']['billing_address_1']);
        unset($fields['billing']['billing_address_2']);
        unset($fields['billing']['billing_company']);
        unset($fields['billing']['billing_city']);
        unset($fields['billing']['billing_postcode']);
        unset($fields['billing']['billing_country']);
        unset($fields['billing']['billing_state']);
    }
    return $fields;
}

 

دیدگاه‌ها 2

  1. سلام – 2تا سوال داشتم..
    1- فیلد کد پستی جز فیلدهایی هست که باید پر شه .. چطور میتونم اون فیلد رو غیر ضروری کنم ؟
    2-چطور میتونم مثلا فیلد انتخاب استان رو قبل از انتخاب شهر بیارم ؟
    تشکر

    1. یوسف پور امینیان مدیر 9 سال پیش پاسخ

      برای کد پستی باید کد زیر رو در فانکشن قرار بدید

      add_filter( 'woocommerce_checkout_fields' , 'WooCommerce_EDD_Checkout' );
      function WooCommerce_EDD_Checkout( $fields ) {

      global $woocommerce;
      $hasPhysicalProduct = false;

      if ( ! empty( $woocommerce->cart->cart_contents ) ) {

      $cart = $woocommerce->cart->get_cart();
      foreach ( $cart as $key => $values ) {

      $_product = get_product( $values['variation_id'] ? $values['variation_id'] : $values['product_id'] );

      if ( ! empty( $_product ) && $_product->exists() && $values['quantity'] > ۰ ) {

      if ($_product->virtual == 'no' && $_product->downloadable == 'no') {
      $hasPhysicalProduct = true;
      break;
      }
      }
      }
      }

      if ($hasPhysicalProduct == false) {
      unset($fields['billing']['billing_postcode']);
      }
      return $fields;
      }

      برای اینکه استان رو قبل از شهر بیارید باید قالبتون یکم دست کاری شه .

دیدگاه خود را بنویسید

لطفاً دیدگاه خود را درباره این نوشته برای ما ارسال کنید. نشانی ایمیل شما منتشر نخواهد شد.

۰/۲۰۰۰