Advertisement
daymobrew

WooCommerce Checkout - check for non-virtual products

Apr 1st, 2015
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.76 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: WooCommerce - Minimal Required Fields
  4. Plugin URI: http://www.damiencarbery.com
  5. Description: Experiment with the minimal number of fields required to complete PayPal payment.
  6. Author: Damien Carbery
  7. Version: 0.2
  8.  
  9. $Id: $
  10. */
  11.  
  12.  
  13. // See: http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
  14. add_filter( 'woocommerce_checkout_fields' , 'wmrf_remove_checkout_fields' );
  15.  
  16. // Our hooked in function - $fields is passed via the filter!
  17. function wmrf_remove_checkout_fields( $fields ) {
  18.     global $woocommerce;
  19.    
  20.     $cart_has_physical_products = false;
  21.     foreach ( $woocommerce->cart->get_cart() as $cart_item_key => $cart_item ) {
  22.         if (!$cart_item['data']->is_virtual()) {
  23.             $cart_has_physical_products = true;
  24.         }
  25.     }
  26.    
  27.     if (!$cart_has_physical_products) {
  28.     // Remove all billing fields except the email field.
  29.     unset($fields['billing']['billing_first_name']);
  30.     unset($fields['billing']['billing_last_name']);
  31.     unset($fields['billing']['billing_company']);
  32.     unset($fields['billing']['billing_address_1']);
  33.     unset($fields['billing']['billing_address_2']);
  34.     unset($fields['billing']['billing_city']);
  35.     unset($fields['billing']['billing_postcode']);
  36.     unset($fields['billing']['billing_country']);
  37.     unset($fields['billing']['billing_state']);
  38.     unset($fields['billing']['billing_phone']);
  39.    
  40.     unset($fields['order']['order_comments']);
  41.     }
  42.    
  43.     return $fields;
  44. }
  45.  
  46.  
  47. // Hide the 'Additional Information' section (that contains the 'order_comments' field.
  48. add_filter('woocommerce_enable_order_notes_field', 'wmrf_remove_additional_info_section');
  49.  
  50. function wmrf_remove_additional_info_section($yes) {
  51.     return false;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement