I'm trying to add this basic code to add a new field to the check out page. However, it seems to disable the place order button. Here is the code:
/**
* Add the field to the checkout
*/
add_action( 'woocommerce_after_order_notes', 'my_custom_checkout_field' );
function my_custom_checkout_field( $checkout ) {
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Were you assisted with this order?'),
'placeholder' => __('Please enter the name of your rep here'),
), $checkout->get_value( 'my_field_name' ));
echo '</div>';
}
You just need to remember to add the start echo'<div>' tag for your field options div. Otherwise it disables the woo-commerce functionality on the page.
add_action('woocommerce_after_order_notes','my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
//need to remember echo start tag here!
echo '<div id="my_custom_checkout_field">';
woocommerce_form_field( 'name_of_child', array(
'type' => 'text',
'class' => array('my-field-class form-row-wide'),
'label' => __('Name of Child'),
'placeholder' => __('Enter something'),
), $checkout->get_value( 'name_of_child' ));
echo '</div>';
}
I'm using Business Lounge theme by RT themes with Elementor.
Wordpress version is current (5.2.1)
On the team page (Demo: https://businesslounge-demo.rtthemes.com/our-team/) there is a list of cards of team members. I want to change the order of the team members to an option that is not currently selectable.
The team member list is done with a shortcode [staff_box]
In Elementor edit mode I looks like this:
Edit:
The edit form is defined in
wp-content/plugins/businesslounge-extensions/inc/elementor-addons/staff.php
<?php
namespace Elementor;
// ...
class Widget_RT_Staff extends Widget_Base {
// ...
protected function _register_controls() {
// ...
$this->add_control(
'list_orderby',
[
'label' => esc_html_x( 'List Order By', 'Admin Panel','businesslounge' ),
'description' => esc_html_x('Sorts the posts by this parameter', 'Admin Panel','businesslounge' ),
'type' => Controls_Manager::SELECT,
'default' => "date",
"options" => array(
'date' => esc_html_x('Date',"Admin Panel","businesslounge"),
'author' => esc_html_x('Author',"Admin Panel","businesslounge"),
'title' => esc_html_x('Title',"Admin Panel","businesslounge"),
'modified' => esc_html_x('Modified',"Admin Panel","businesslounge"),
'ID' => esc_html_x('ID',"Admin Panel","businesslounge"),
'rand' => esc_html_x('Randomized',"Admin Panel","businesslounge"),
)
]
);
// ...
}
// ...
}
Plugin::instance()->widgets_manager->register_widget_type( new Widget_RT_Staff() );
The edit form is defined in `wp-content/plugins/businesslounge-extensions/inc/editor/staff_box.php`
like so
<?php
vc_map(
array(
'base' => 'staff_box',
'name' => _x( 'Team', 'Admin Panel','businesslounge' ),
'icon' => 'rt_theme rt_team',
'category' => array(_x( 'Content', 'Admin Panel','businesslounge' ), _x( 'Theme Addons', 'Admin Panel','businesslounge' )),
'description' => _x( 'Displays team members', 'Admin Panel','businesslounge' ),
'params' => array(
// ...
array(
'param_name' => 'list_orderby',
'heading' => _x( 'List Order By', 'Admin Panel','businesslounge' ),
"description" => _x("Sorts the posts by this parameter",'Admin Panel','businesslounge'),
'type' => 'dropdown',
"value" => array(
_x('Date','Admin Panel','businesslounge') => 'date',
_x('Author','Admin Panel','businesslounge') => 'author',
_x('Title','Admin Panel','businesslounge') => 'title',
_x('Modified','Admin Panel','businesslounge') => 'modified',
_x('ID','Admin Panel','businesslounge') => 'ID',
_x('Randomized','Admin Panel','businesslounge') => 'rand',
),
'save_always' => true
),
// ...
The output is defined in
wp-content/plugins/businesslounge-extensions/inc/shortcodes/staff_box.php
like so:
<?php
function rt_staff( $atts, $content = null ) {
// ...
//defaults
extract(shortcode_atts(array(
"id" => 'staff-'.rand(100000, 1000000),
"class" => "",
"list_layout" => "1/1",
"list_orderby" => "date",
"list_order" => "DESC",
"ids" => array(),
"box_style" => ""
), $atts));
// ...
//general query
$args=array(
'post_status' => 'publish',
'post_type' => 'staff',
'orderby' => $list_orderby,
'order' => $list_order,
'showposts' => 1000
);
// ...
$theQuery = query_posts($args);
// ...
What I want to do:
Add an option 'post_name' to the select box so that I can sort the team by a different field. I want to add
'Post name' => 'post_name',
How can I do this without changing the original source code?
I already have the child theme of business_lounge theme activated.
Do I need a custom extension for this?
You'd have to modify the original code.
You can't override the function unless the author applied a filter to the value returned, or used an action.
As gael notes in his answer, you can soften the blow of losing changes on updates by copying the original code into your child theme's functions.php then renaming the function - for e.g. to my_rt_staff() before adding in your modifications.
You would however still need to call the my_rt_staff() in the plugin instead of rt_stuff and you would have to make this change whenever the plugin was updated, but you wouldn't lose your code.
(Perhaps you could change the "list_orderby" => "date" in the default shortcode attributes to "list_orderby" => "post_name", as default in your modified my_rt_staff() method so it orders by name as default instead of date)
However, this does not help much in your specific circumstance, as the ideal modification you need to make is to the control itself, on the _register_controls() method in the Widget_RT_Staff class. You can override this by extending Widget_RT_Staff but you would still need to call your new class which results in you modifying the plugin code.
Without seeing how the Widget_RT_Staff class affects the shortocde, I can't be certain this would work, but based on the rt_staff() method, if you use the shortcode as [staff_box orderby="post_name"] you may get your intended result without having to touch any code.
You should be able to modify your plugin without losing update abilities by 'overriding' the function as described here:
https://stackoverflow.com/a/40856197/3623080
Make a copy of the function in your child-theme's functions.php, customize and rename it, use it in place of the original function.
Hope it will help
I am trying to add some extra fields in theme my login Plugin Wordpress.
I am done with the documentation of the theme.
The extra fields aren't been saved on database. I have added the extra fields in the db as well but still the data are not been saved in db
Any Suggestion?
You need to use custom type not text and first_name
function add_tml_registration_form_fields() {
tml_add_form_field( 'register', 'custom_1', array(
'type' => 'custom',
'label' => 'First Name 1 ',
'value' => tml_get_request_value( 'first_name_test', 'post' ),
'id' => 'first_name_test',
'priority' => 15,
) );
tml_add_form_field( 'register', 'custom_2', array(
'type' => 'custom',
'label' => 'Last Name 1',
'value' => tml_get_request_value( 'last_name_test', 'post' ),
'id' => 'last_name_test',
'priority' => 15,
) );
}
add_action( 'init', 'add_tml_registration_form_fields' );
Read this
https://docs.thememylogin.com/article/104-function-tmladdformfield
Adding placeholder to Postcode billing field in Woocommerce.
In core class-wc-countries.php
'postcode' => array(
'label' => __( 'Postcode / ZIP', 'woocommerce' ),
'required' => true,
'class' => array( 'form-row-last', 'address-field' ),
'clear' => true,
'validate' => array( 'postcode' ),
'autocomplete' => 'postal-code',
),
So there is no way to override it woocommerce_billing_fields filter. Why some fields have placeholder key but other not? Some fields have only labels, some only placeholders and some have both. I don't get logic behind this.
So my question is: how to add placeholder text to Postcode field. I can do it with Javascript, but that seams not natural. Also I can modify core, which is even worse then Javascript solution. What else can I do?
As suggested by #Ash Patel we can do it like this:
add_filter( 'woocommerce_checkout_fields', function($fields){
$fields['billing']['billing_postcode']['placeholder'] = __('My Post Code', 'woocommerce');
return $fields;
} );
And for shipping
add_filter( 'woocommerce_shipping_fields', function($fields){
$fields['shipping_postcode']['placeholder'] = __('My Post Code', 'woocommerce');
return $fields;
} );
add below code into your function.php for adding/updating postal code for checkout and edit screen.
//on edit address screen
function filter_woocommerce_billing_fields( $wooccm_billing_fields, $int ) {
$wooccm_billing_fields['billing_postcode']['placeholder'] = __('My Post Code', 'woocommerce');;
return $wooccm_billing_fields;
};
add_filter( 'woocommerce_billing_fields', 'filter_woocommerce_billing_fields', 10, 2 );
add_action('woocommerce_checkout_fields', 'update_placeholder_checkout_form_billing');
function update_placeholder_checkout_form_billing($wcCheckout_fields) {
$wcCheckout_fields['billing']['billing_postcode'] = array(
'label' => 'Postcode / ZIP',
'placeholder' => _x('My Post Code', 'placeholder', 'woocommerce'),
'required' => true,
'class' => array('checkout-billing-postal-code')
);
return $wcCheckout_fields;
}
Im trying to echo a $var in a function array in WP. I need to have a field on the Woocommerce checkout (accomplished) with a VALUE from a $_SESSION. The checkout field looks like this:
// Our hooked in function - $fields is passed via the filter!
public function VAT_override_checkout_fields( $fields ) {
$fields['billing']['VAT_cui'] = array(
'label' => __('Domæne', 'woocommerce'),
'placeholder' => _x('Intet Valgt', 'placeholder', 'woocommerce'),
'required' => false,
'class' => array('form-row-wide'),
'clear' => true,
'type' => 'select',
'options' => array(
'kobdomain' => __('echo $MYVAR', 'woocommerce' ),
)
);
return $fields;
}
I understand i doesnt work, but im stuck :(
Problem is i need the return $fields input value to be filled with a string from my Session. I think its possible with the SELECT OPTION field, but as you can see, i dunno how to echo value in it.