• Hi, this is a great plugin! However I can’t find the way to change the position of new field that I have created with your plugin. I have test changing the Order number but the field is in the end always.
    How can I do in order to change its position?

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • First of all – big ups to the plugin author – a very helpful little plugin, thank you.

    As for re-ordering, I was able to do so with the following code, added to your functions file.

    
    	
    /*
     * Order the new fields at checkout.
    */
    
    function render_extra_checkout_fields( $fields ) {
          
    	   $args = array(
                'post_type' => Woocommerce_Custom_Registration_Form_Elements_Post_Type::$cpt,
                'post_status' => 'publish',
                'numberposts' => -1,
                'order' => 'ASC',
                'orderby' => 'meta_value_num',
                'meta_key' => 'woo_custom_register_element_order'
            );
            $query = new WP_Query($args);
    	
    	// var_dump($args);  // show what is available
     
        foreach ($query->get_posts() as $post) {
                $element = get_post_meta($post->ID, 'woo_custom_register_element', true);
                
                // place our new fields under the Additional Information column 
                // https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2
    
    	    $fields['order'][ $key ] = $element;
    			
           // I am not sure we need these fields - the plugin author can clarify	   
           //$classname = Woocommerce_Custom_Registration_Utils::getClassNameByElement($element['type']);
                //$classname::elementRenderingCheckout($element, $fields);
            }
        return $fields;
    }
    add_filter( 'woocommerce_checkout_fields', 'render_extra_checkout_fields', 10, 1 );
    
    

    While the above appears to work fine, I was not able to remove the plugin author’s original fields from the checkout ‘Billing’ section because the filter that is used is protected within a class I was not able to filter:

    Thus the following doesn’t work:

    remove_filter( 'woocommerce_checkout_fields', 'form_elements_rendering_checkout');

    That code comes from line 29 in the file https://plugins.trac.www.ads-software.com/browser/woo-custom-registration/tags/1.0.0/includes/registration-form/class-woocommerce-custom-registration-form-elements-rendering.php

    	    private function init_hook()
    	    {
    	        $this->loader->add_action('woocommerce_register_form_start', $this, 'form_elements_rendering_registration');
    	        $this->loader->add_action('show_user_profile', $this, 'extra_user_profile_fields_admin');
    	        $this->loader->add_action('edit_user_profile', $this, 'extra_user_profile_fields_admin');
    	        $this->loader->add_action('woocommerce_edit_account_form', $this, 'extra_user_profile_fields_public');
    	        $this->loader->add_filter('woocommerce_checkout_fields', $this, 'form_elements_rendering_checkout');
    	    }

    Perhaps the author can clarify how we can filter out that final line?

    Meanwhile, you can remove the duplicate fields from showing at the ‘billing’ section by commenting the code for that line in the plugin file (of course this is not recommended as it will be overwritten if the plugin gets updated.

    (comment out line 29 in the file https://plugins.trac.www.ads-software.com/browser/woo-custom-registration/tags/1.0.0/includes/registration-form/class-woocommerce-custom-registration-form-elements-rendering.php)

    • This reply was modified 5 years, 1 month ago by Iamhere.
    • This reply was modified 5 years, 1 month ago by Iamhere.
    • This reply was modified 5 years, 1 month ago by Iamhere.
    • This reply was modified 5 years, 1 month ago by Iamhere.

    In addition to the above suggestion, you can also move the form elements simply by using jquery – but it’s not as fast.

    // Move extra registration fields 
    function my_custom_header_code12002(){
    	if (is_checkout): ?>
    		<script type="text/javascript">
                jQuery(window).load(function () {
                    jQuery('.woocommerce-account-fields .create-account').appendTo('.woocommerce-additional-fields');
    // the appendTo place here is on the right column, use Firebox to find the CSS class to where you want to move it
    				
                    ;}
                );
            </script>
    	<? endif; 
    }
    add_action('wp_head', 'my_custom_header_code12002');
    
    • This reply was modified 5 years, 1 month ago by Iamhere.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Field Order’ is closed to new replies.