1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
/** * Child-Theme functions and definitions */ function logg($o){ print '<pre>'; print_r($o); print '</pre>'; exit(); } add_action( 'wp_footer', 'find_filters' ); function find_filters($filter_name) { global $wp_filter; //logg($wp_filter[$filter_name]); //logg($this->checkout_fields); } function frank_jewelry_store_child_scripts() { wp_enqueue_style( 'frank-jewelry-store-parent-style', get_template_directory_uri(). '/style.css' ); } add_action( 'wp_enqueue_scripts', 'frank_jewelry_store_child_scripts' ); // woocommerce password strength function wc_ninja_remove_password_strength() { if ( wp_script_is( 'wc-password-strength-meter', 'enqueued' ) ) { wp_dequeue_script( 'wc-password-strength-meter' ); } } add_action( 'wp_print_scripts', 'wc_ninja_remove_password_strength', 100 ); //地址資料一定要在這裡改,如果在woocommerce_checkout_fields改會無效 add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' ); // Our hooked in function - $address_fields is passed via the filter! function custom_override_default_address_fields( $address_fields ) { $address_fields['address_1']['required'] = false; $address_fields['address_1']['label'] = '地址或超商資料'; $address_fields['address_1']['placeholder'] = '地址或超商資料'; $address_fields['state']['required'] = false; $address_fields['city']['required'] = false; $address_fields['postcode']['required'] = false; return $address_fields; } function sort_checkout_fields($fields, $key){ $order = array( $key . "_last_name", $key . "_first_name", $key . "_email", $key . "_phone", //$key . "_company", $key . "_country", $key . "_state", $key . "_city", $key . "_postcode", $key . "_address_1" //$key . "_address_2", ); foreach($order as $field){ $ordered_fields[$field] = $fields[$key][$field]; } $ordered_fields[$key . "_last_name"]['class'] = array('form-row-first'); $ordered_fields[$key . "_last_name"]['clear'] = 0; $ordered_fields[$key . "_first_name"]['class'] = array('form-row-last'); $ordered_fields[$key . "_first_name"]['clear'] = 1; return $ordered_fields; } // Hook in add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields', 11); // Our hooked in function - $fields is passed via the filter! function custom_override_checkout_fields( $fields ) { $fields['billing'] = sort_checkout_fields($fields, 'billing'); /* $fields['billing']['cod_cvs_info'] = array( 'label' => __('貨到付款超商資料', 'woocommerce'), 'placeholder' => _x('貨到付款超商資料', 'placeholder', 'woocommerce'), 'required' => false, 'class' => array('form-row-wide'), 'clear' => true ); */ return $fields; } /** * Display field value on the order edit page */ add_action( 'woocommerce_admin_order_data_after_shipping_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 ); function my_custom_checkout_field_display_admin_order_meta($order){ echo '<p><strong>'.__('貨到超商資料').':</strong> ' . get_post_meta( $order->id, '_cod_cvs_info', true ) . '</p>'; } |
Reference:
- Official Tutorials
https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ - Sorting for checkout fields
https://wordpress.stackexchange.com/questions/78339/how-to-reorder-billing-fields-in-woocommerce-checkout-template - Woocommerce Hooks
https://docs.woocommerce.com/wc-apidocs/hook-docs.html - Other tutorial:
http://uploadwp.com/customizing-the-woocommerce-checkout-page/