I use the Admin Order Page of WooCommerce to book certain products in a box office.
I want to make certain customer data required fields. (Like first_name,last_name,email etc.)
That the order can only be processed (saved) with this data entered in the billing information field.
I haven't found any solution on the internet that makes the fields in the admin panel required. Only found solutions for the frontend.
Any ideas?
this will prevent "Save order" button from firing if first_name is empty in the billing section.
add_filter('woocommerce_admin_billing_fields', 'woocommerce_require_admin_billing_fields');
function woocommerce_require_admin_billing_fields( $fields ){
$fields['first_name']['custom_attributes'] = array( 'required' => 'required' );
// $fields['last_name']['custom_attributes'] = array( 'required' => 'required' ); // for last_name
return $fields;
}
but keep in mind that this prevention is only on client side and will not work on older browsers...
I can't find a way to stop post from saving on the server side.
Related
I've created a custom field in Rank Math...
add_action( 'rank_math/vars/register_extra_replacements', function(){
rank_math_register_var_replacement(
'op_shortcode',
[
'name' => esc_html__( 'OP ACF Field', 'rank-math' ),
'description' => esc_html__( 'Custom ACF field from ACF shortcodes.', 'rank-math' ),
'variable' => 'op_shortcode(field-name)',
'example' => esc_html__( 'Chrisad field value', 'rank-math' ),
],
'get_op_shortcode_callback'
);
});
function get_op_shortcode_callback( $shortcodename, $post_id ) {
global $post;
$post_id = "option"; // options page
$shortcodename = get_field( $shortcodename, $post_id, true );
return $shortcodename;
}
... it works in the frontend but I can't get it to be previewable in the backend metabox.
I wrote to Rank Math and the answer they gave first was, "There’s no additional code to be added to the filter since the custom variable is already working on the front end. For the preview to work, you need to ensure that the current content editor you are working on has WordPress editor support." (Which it does as far as I know because every other Rank Math variable is showing in the preview metabox).
Then they said, "When this happens it means that the custom variable you created contains code that cannot be rendered in the backend because the data is still not yet available." (I don't know what this means.)
And then finally, "The following article explains the default WordPress hooks firing sequence: http://rachievee.com/the-wordpress-hooks-firing-sequence/. Beyond that article, you will have to research further into how to get the variable to load. ACF support/forums might be able to help." (That's a 2015 article on hooks firing sequence which leads me to believe that there is a hook firing out of sequence but I can't figure it out).
I am just looking to see if anyone has any idea how to get the custom field I've registered to show up in the preview metabox in the backend (it is showing in the frontend).
Hope that makes sense.
Any help or insight is appreciated.
I am using a paid theme which is using Redux Framework. I am trying to add a new field in Footer Options. I am able to add this field in options but only in print_r() function it is showing not showing in Themes Options Panel.
function add_another_section_bl($sections){
$sections[12]['fields'][] = array(
'id' => 'rd_footer_message_1',
'type' => 'textarea',
'title' => __('Text 2 to display in footer under bar', 'thefoxwp'),
'subtitle' => __('write your copyright information or anything you\'d like.', 'thefoxwp'),
'validate' => 'html', //see http://codex.wordpress.org/Function_Reference/wp_kses_post
'default' => 'Copyright 2015 Tranmautritam\'s team | All Rights Reserved'
);
return $sections;}
add_filter("redux/options/rd_data/register", 'add_another_section_bl');
In array data it is showing the required data but not in Options Panel in wordpress dashboard.
Kindly get me out of this.
There's a much simpler approach if you use the Redux API:
https://docs.redux.io/configuration/redux-api.html
You can modify, add, update any section or field before it is rendered. Please note, you may have to put your code within hooks. Also please note the Redux 4 method names have changed from setArgs to set_args (camelcase to non).
Otherwise, you will have all you need.
How add field to the email report??
http://www.evernote.com/l/Ac2uV87BrP9G9L7eKZplR1x3LrsGs-Yfsm8/
and
how add field to the order page
http://www.evernote.com/l/Ac1m-Ah7v71P9Zv3dmbIPXlHdxnrr9T7WkA/
You can add a field in email report using the following code
function wdm_custom_order_item_details($total_rows, $object){
$total_rows['custom Message']= array(
'label' => 'My Custom Message',
'value' => 'Custom information i want to see in order emails',
);
return $total_rows;
}
add_filter('woocommerce_get_order_item_totals','wdm_custom_order_item_details',10,2);
here the output will be
and to add field to the order page use this code
function wdm_admin_order_panel_after_shipping_address($order){
//use $order to get the details you want related to that order and display it here.
echo "<div><h4>My Custom Information</h4><p>Custom information i want to see in order details</p></div>";
}
//to add text after Shipping address of an order in admin panel
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'wdm_admin_order_panel_after_shipping_address' ,10,1);
here the output will be
Tested. Let me know if it worked for you.
I have the user-signup disabled on my Drupal 7 website. Only the administrator can create accounts.
I want to add custom fields for a user depending on the role the user has been assigned by the administrator.Now I want to add some fields to the registration system that depend to the role that the admin chosen.
eg: If the admin has created a user account with role A and another account with role B.
When the users log-in, user A should be asked to enter phone number whereas the second user should be asked to enter home address.
I tried profile2 module but I could not achieve what I wanted.
Use the User_Role_Field module that does exactly what you want. If you need better configuration per role access use the Field_Permissions module.
Notice that after user registration the fields are displayed under user profile and not in registration form. Your question is a bit confusing...
There's the conditional_fields module, which sounds like it'll get you most of the way there.
Failing that, I'd say your best bet is to use hook_form_alter() in a custom module.
Something like:
function yourmodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'user_register') {
// Define the phone field.
$form['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#size' => 30,
'#maxlength' => 30,
'settings' => array(
'#states' => array(
// Hide this field when role A isn't checked.
'invisible' => array(
':input[role="A"]' => array('checked' => FALSE),
),
),
),
);
// Define home address field
// [copy the snippet above & tweak to suit...]
}
}
This is unlikely to work out of the box (I've no drupal environment to hand), but with some adaptation it should get you most of the way there.
The "':input[role="A"]' => array('checked' => TRUE)," line will need the most work, i.e. "role" will need to match the name attribute of the "Roles" checkboxes, and the "A" will need to correspond to A's actual value when checked.
If you've no other form_alter usage in your module, you might also consider replacing the function name with "yourmodule_user_register_form_alter".
If a user clicks the "update" link in their recurring fees table, then decides not to make any changes and clicks Cancel instead of Update, they get access denied because the cancel link redirects to the admin view of recurring fees, not back to the user view. This is with the authorize.net handler, the URL in question is like the following:
example.com/user/263/recurring/715/cancel/authorizenet_cim?destination=user/263/recurring-fees
This is the code I got when I am doing research, I changed my code according to the mentioned below,but it does't work for me any help!
In uc_recurring.uc_authorizenet.inc around lines 140-147:
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update'),
// '#suffix' => l(t('Cancel'), 'admin/store/orders/recurring/view/fee/' . $rfid),
'#suffix' => l(t('Cancel'), $_SERVER['HTTP_REFERER']), //This is the line I have added
);
It is very easy, you can add the Rules, it will redirect.