Woocommerce Checkout page customization

/**
 * 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:

  1. Official Tutorials
    https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
  2. Sorting for checkout fields
    https://wordpress.stackexchange.com/questions/78339/how-to-reorder-billing-fields-in-woocommerce-checkout-template
  3. Woocommerce Hooks
    https://docs.woocommerce.com/wc-apidocs/hook-docs.html
  4. Other tutorial:
    http://uploadwp.com/customizing-the-woocommerce-checkout-page/