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.