Woocommerce has a default tracking form that lets customers see their order status.
But I'm looking to replace the Email request with Billing Phone Number (which value should be billing_phone)
Any idea how to change? It seems it's not that easy to change order_email with billing_phone.
Here is the part in woocommerce/order/tracking-form.php
<p class="form-row form-row-first">
<label for="orderid">
<?php esc_html_e( 'Order ID', 'woocommerce' ); ?>
</label>
<input class="input-text" type="text" name="orderid" id="orderid" value="<?php echo isset( $_REQUEST['orderid'] ) ? esc_attr( wp_unslash( $_REQUEST['orderid'] ) ) : ''; ?>" placeholder="<?php esc_attr_e( 'Found in your order confirmation email.', 'woocommerce' ); ?>" />
</p>
<?php // #codingStandardsIgnoreLine ?>
<p class="form-row form-row-last">
<label for="order_email">
<?php esc_html_e( 'Billing email', 'woocommerce' ); ?>
</label>
<input class="input-text" type="text" name="order_email" id="order_email" value="<?php echo isset( $_REQUEST['order_email'] ) ? esc_attr( wp_unslash( $_REQUEST['order_email'] ) ) : ''; ?>" placeholder="<?php esc_attr_e( 'Email you used during checkout.', 'woocommerce' ); ?>" />
</p>
<?php // #codingStandardsIgnoreLine ?>
<div class="clear"></div>
Thank you all.
There is no simple solution for this. Since the core WC process is to get the email input and to compare it against the order billing email.
Unfortunately, I could not find an easy way to override it.
But you can consider adjusting the copy of the template file in your theme folder to get a response from your code rather than WC.
to do this, you will need:
Change the nonce field in the form, so the action will be customized (then you will be able to "catch" and handle it from the server-side:
wp_nonce_field( 'woocommerce-order_tracking_custom', 'woocommerce-order-tracking-custom-nonce' );
Copy (to your functions.php) and adjust the method output from class-wc-shortcode-order-tracking.php
public static function output( $atts ) {
// Check cart class is loaded or abort.
if ( is_null( WC()->cart ) ) {
return;
}
...
...
wc_get_template( 'order/form-tracking.php' );
}
To something like this:
add_action('init', 'handle_tracking_request');
function handle_tracking_request( ) {
// Check cart class is loaded or abort.
if ( is_null( WC()->cart ) ) {
return;
}
$nonce_value = wc_get_var( $_REQUEST['woocommerce-order-tracking-custom-nonce'], wc_get_var( $_REQUEST['_wpnonce'], '' ) );
if ( isset( $_REQUEST['orderid'] ) && wp_verify_nonce( $nonce_value, 'woocommerce-order_tracking_custom' ) ) {
$order_id = empty( $_REQUEST['orderid'] ) ? 0 : ltrim( wc_clean( wp_unslash( $_REQUEST['orderid'] ) ), '#' ); // WPCS: input var ok.
$order_phone = empty( $_REQUEST['order_phone'] ) ? '' : sanitize_email( wp_unslash( $_REQUEST['order_phone'] ) );
if ( ! $order_id ) {
wc_print_notice( __( 'Please enter a valid order ID', 'woocommerce' ), 'error' );
} elseif ( ! $order_phone ) {
wc_print_notice( __( 'Please enter a valid phone', 'woocommerce' ), 'error' );
} else {
$order = wc_get_order( apply_filters( 'woocommerce_shortcode_order_tracking_order_id', $order_id ) );
if ( $order && $order->get_id() && ( $order->get_billing_phone() ) === strtolower( $order_phone ) ) {
do_action( 'woocommerce_track_order', $order->get_id() );
wc_get_template(
'order/tracking.php', array(
'order' => $order,
)
);
return;
} else {
wc_print_notice( __( 'Sorry, the order could not be found. Please contact us if you are having difficulty finding your order details.', 'woocommerce' ), 'error' );
}
}
}
wc_get_template( 'order/form-tracking.php' );
}
I didn't tested it, and hope it will work. You may need to adjust it further. let me know if it helped you
Related
I have tried this method creating a separate plugin, but it is not working, can anyone help me out with this? Please. I have a restricted site. without filling out proper legal documents the user will not be approved from the WordPress dashboard. But when submitting for registration everything is working well, but the file is not uploading or not showing on the dashboard use profile page.
`
add_action( 'register_form', 'crf_registration_form' );
function crf_registration_form() {
$year = ! empty( $_POST['legal_documents'] ) ? intval( $_POST['legal_documents'] ) : '';
?>
<p>
<label for="legal_documents"><?php esc_html_e( 'National ID/Passport/Driving License', 'crf' ) ?><br/>
<input type="file"
id="legal_documents"
name="legal_documents"
value="<?php echo esc_attr( $documents ); ?>"
class="input"
/>
</label>
</p>
<?php
}
add_filter( 'registration_errors', 'crf_registration_errors', 10, 3 );
function crf_registration_errors( $errors, $sanitized_user_login, $user_email ) {
if ( empty( $_POST['legal_documents'] ) ) {
$errors->add( 'legal_documents_error', __( '<strong>ERROR</strong>: Please upload your legal documents to have active account.', 'crf' ) );
}
return $errors;
}
add_action( 'user_register', 'crf_user_register' );
function crf_user_register( $user_id ) {
if ( ! empty( $_POST['legal_documents'] ) ) {
update_user_meta( $user_id, 'legal_documents', intval( $_POST['legal_documents'] ) );
}
}
/**
* Back end registration
*/
add_action( 'user_new_form', 'crf_admin_registration_form' );
function crf_admin_registration_form( $operation ) {
if ( 'add-new-user' !== $operation ) {
// $operation may also be 'add-existing-user'
return;
}
$year = ! empty( $_POST['legal_documents'] ) ? intval( $_POST['legal_documents'] ) : '';
?>
<h3><?php esc_html_e( 'Verification documents', 'crf' ); ?></h3>
<table class="form-table">
<tr>
<th><label for="legal_documents"><?php esc_html_e( 'legal_documents', 'crf' ); ?></label> <span class="description"><?php esc_html_e( '(required)', 'crf' ); ?></span></th>
<td>
<input type="file"
id="legal_documents"
name="legal_documents"
value="<?php echo esc_attr( $documents ); ?>"
class="regular-text"
/>
</td>
</tr>
</table>
<?php
}
add_action( 'user_profile_update_errors', 'crf_user_profile_update_errors', 10, 3 );
function crf_user_profile_update_errors( $errors, $update, $user ) {
if ( $update ) {
return;
}
if ( empty( $_POST['legal_documents'] ) ) {
$errors->add( 'legal_documents_error', __( '<strong>ERROR</strong>: Please upload your valid documents', 'crf' ) );
}
}
add_action( 'edit_user_created_user', 'crf_user_register' );
/**
* Profile Display
*/
add_action( 'show_user_profile', 'crf_show_extra_profile_fields' );
add_action( 'edit_user_profile', 'crf_show_extra_profile_fields' );
function crf_show_extra_profile_fields( $user ) {
?>
<h2><?php esc_html_e( 'Verification documents', 'crf' ); ?></h2>
<table class="form-table">
<tr>
<th><label for="legal_documents"><?php esc_html_e( 'Legal Documents', 'crf' ); ?></label></th>
<td><?php echo esc_html( get_the_author_meta( 'legal_documents', $user->ID ) ); ?></td>
</tr>
</table>
<?php
}
`
I have tried this code snippets but the file is not receiving on the WordPress user page, it is showing 0.
This is the code to add a new field in Dokan:
Here is also the link to how it works : https://nayemdevs.com/how-to-add-a-new-field-on-product-upload-form-dokan-multivendor/
Please can someone tell me how to add a drop down menu for attributes instead of a field.
I want to add a drop down menu of specific attributes in Dokan POP UP
Este codigo va en el tema hijo activo .
Function.php
/*
* Adding extra field on New product popup/without popup form
*/
add_action( 'dokan_new_product_after_product_tags','new_product_field',10 );
function new_product_field(){ ?>
<div class="dokan-form-group">
<input type="text" class="dokan-form-control" name="new_field" placeholder="<?php esc_attr_e( 'Product Code', 'dokan-lite' ); ?>">
</div>
<?php
}
/*
* Saving product field data for edit and update
*/
add_action( 'dokan_new_product_added','save_add_product_meta', 10, 2 );
add_action( 'dokan_product_updated', 'save_add_product_meta', 10, 2 );
function save_add_product_meta($product_id, $postdata){
if ( ! dokan_is_user_seller( get_current_user_id() ) ) {
return;
}
if ( ! empty( $postdata['new_field'] ) ) {
update_post_meta( $product_id, 'new_field', $postdata['new_field'] );
}
}
/*
* Showing field data on product edit page
*/
add_action('dokan_product_edit_after_product_tags','show_on_edit_page',99,2);
function show_on_edit_page($post, $post_id){
$new_field = get_post_meta( $post_id, 'new_field', true );
?>
<div class="dokan-form-group">
<input type="hidden" name="new_field" id="dokan-edit-product-id" value="<?php echo esc_attr( $post_id ); ?>"/>
<label for="new_field" class="form-label"><?php esc_html_e( 'Product Code', 'dokan-lite' ); ?></label>
<?php dokan_post_input_box( $post_id, 'new_field', array( 'placeholder' => __( 'product code', 'dokan-lite' ), 'value' => $new_field ) ); ?>
<div class="dokan-product-title-alert dokan-hide">
<?php esc_html_e( 'Please enter product code!', 'dokan-lite' ); ?>
</div>
</div> <?php
}
// showing on single product page
add_action('woocommerce_single_product_summary','show_product_code',13);
function show_product_code(){
global $product;
if ( empty( $product ) ) {
return;
}
$new_field = get_post_meta( $product->get_id(), 'new_field', true );
if ( ! empty( $new_field ) ) {
?>
<span class="details"><?php echo esc_attr__( 'Product Code:', 'dokan-lite' ); ?> <strong><?php echo esc_attr( $new_field ); ?></strong></span>
<?php
}
}
I’m trying to add an extra field on dokan registration for vendors to upload an identification document.. i found the code specified for adding an extra field to the form but it is for a "text" input type… i changed the input type from "text" to "file"
<p class="form-row form-group form-row-wide">
<label for="veri-file"><?php esc_html_e( 'Upload Verification ID', 'dokan-custom-codes' ); ?><span class="required">*</span></label>
<input type="file" class="verifile" name="veri_file" id="veri_file" accept="image/png, image/jpeg" value="upload"<?php if ( ! empty( $postdata['veri_file'] ) ) echo esc_attr($postdata['veri_file']); ?>" required="required" />
</p>
and that worked… but the code to save and display the field content on the user backend doesn’t show the image just the same upload box
// save id verification field
I also used below code to show in admin side but image not shown not move to folders
function dokan_custom_seller_registration_required_fields( $required_fields ) {
$required_fields['veri_file'] = __( 'Please upload a valid means of Identification', 'dokan-custom' );
return $required_fields;
};
add_filter( 'dokan_seller_registration_required_fields', 'dokan_custom_seller_registration_required_fields' );
function dokan_custom_new_seller_created( $vendor_id, $dokan_settings ) {
$post_data = wp_unslash( $_POST );
$veri_file = $post_data['veri_file'];
update_user_meta( $vendor_id, 'dokan_custom_veri_file', $veri_file );
}
add_action( 'dokan_new_seller_created', 'dokan_custom_new_seller_created', 10, 2 );
/* Add custom profile fields (call in theme : echo $curauth->fieldname;) */
add_action( 'dokan_seller_meta_fields', 'my_show_extra_profile_fields' );
function my_show_extra_profile_fields( $user ) { ?>
<?php if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
if ( ! user_can( $user, 'dokandar' ) ) {
return;
}
$gst = get_user_meta( $user->ID, 'dokan_custom_veri_file', true );
?>
<tr>
<th><?php esc_html_e( 'Upload Verification ID', 'dokan-lite' ); ?></th>
<td>
<input type="file" name="veri_file" class="verifile" value="<?php echo esc_attr($gst); ?>"/>
<img src=".$gst." height=200 width=300 />
</td>
</tr>
echo "<img src=".$gst." height=200 width=300 />";
<?php
}
add_action( 'personal_options_update', 'my_save_extra_profile_fields' );
add_action( 'edit_user_profile_update', 'my_save_extra_profile_fields' );
function my_save_extra_profile_fields( $user_id ) {
if ( ! current_user_can( 'manage_woocommerce' ) ) {
return;
}
update_usermeta( $user_id, 'dokan_custom_veri_file', $_POST['veri_file'] );
}
I created a custom meta box (author) for a custom post type (books). The box shows up in the admin fine, but I can't figure out how to display the author in my theme.
This is the code used to create the box:
/**
* Adds a meta box to the post editing screen
*/
function prfx_custom_meta() {
add_meta_box( 'prfx_meta', __( 'Book Author', 'prfx-textdomain' ), 'prfx_meta_callback', 'rabe_books', 'side' );
}
add_action( 'add_meta_boxes', 'prfx_custom_meta' );
/**
* Outputs the content of the meta box
*/
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$prfx_stored_meta = get_post_meta( $post->ID );
?>
<p>
<label for="meta-text" class="prfx-row-title"><?php _e( 'Example Text Input', 'prfx-textdomain' )?></label>
</p>
<?php
}
/**
* Saves the custom meta input
*/
function prfx_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'meta-text' ] ) ) {
update_post_meta( $post_id, 'meta-text', sanitize_text_field( $_POST[ 'meta-text' ] ) );
}
}
add_action( 'save_post', 'prfx_meta_save' );
/**
* Adds the meta box stylesheet when appropriate
*/
function prfx_admin_styles(){
global $typenow;
if( $typenow == 'post' ) {
wp_enqueue_style( 'prfx_meta_box_styles', plugin_dir_url( __FILE__ ) . 'meta-box-styles.css' );
}
}
add_action( 'admin_print_styles', 'prfx_admin_styles' ); ?>
And this is what I placed in my template:
<div class="book-author">by:
<?php $book_author = get_post_meta( get_the_ID(), 'meta-text', true );
if (!empty($book_author)) {
echo $book_author;
} elseif (empty($book_author)) {
echo "Why doesnt it work?";
} ?>
</div>
Instead of displaying the author, it displays the text "Why doesnt it work?" which I guess means that the value is empty. But it shouldn't be. What am I doing wrong?
As mevius mentioned, you're issue is here:
<?php _e( 'Example Text Input', 'prfx-textdomain' )?>
http://codex.wordpress.org/Function_Reference/_e
You'll need to assign the box to a data point.
This is a snippet from one of our functions.php file that has this:
function css_metadata_box($object, $box) { ?>
<p>
<label for="custom-css-data">Add custom CSS for this page</label>
<textarea name="custom-css-data" id="custom-css-data" cols="60" rows="25" tabindex="30" style="width: 97%;"><?php
echo esc_html( get_post_meta( $object->ID, 'custom-css', true ), 1 );
?></textarea>
<input type="hidden" name="css_meta_box_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
</p>
<?php }
add_meta_box('css-data-box', 'Page CSS', 'css_metadata_box', 'page', 'normal', 'high');
I seem to have a problem with my meta box saving, not totally sure what I've done wrong. Any help would be greatly appreciated!
Heres my functions file:
add_action( 'add_meta_boxes', 'cd_meta_box_add' );
function cd_meta_box_add()
{
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if ($template_file == 'golf.php')
{
add_meta_box (
'golf-times',
'Golf Opening Times & Prices',
'cd_meta_box_cb',
'page',
'normal',
'high'
);
}
}
function cd_meta_box_cb( $post )
{
$values = get_post_custom( $post->ID );
$times = isset( $values['golf_meta_box_times'] ) ? esc_attr( $values['golf_meta_box_times'][0] ) : '';
$prices = isset( $values['golf_meta_box_prices'] ) ? esc_attr( $values['golf_meta_box_prices'][0] ) : '';
wp_nonce_field( 'golf_meta_box_nonce', 'meta_box_nonce' );
?>
<div style="overflow: hidden;">
<div style="width: 45%; float: left;">
<p><label for="golf_meta_box_times">Opening Times</label></p>
<p><textarea type="text" name="golf_meta_box_times" id="golf_meta_box_times" rows="5" style="width: 90%;" value="<?php echo $times; ?>"> </textarea></p>
</div>
<div style="width: 45%; float: left;">
<p><label for="golf_meta_box_prices">Prices</label></p>
<p><textarea type="text" name="golf_meta_box_prices" id="golf_meta_box_prices" rows="5" style="width: 90%;" value="<?php echo $prices; ?>"> </textarea></p>
</div>
</div>
<?php
}
add_action( 'save_post', 'cd_meta_box_save' );
function cd_meta_box_save( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'golf_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post' ) ) return;
$allowed = array(
'a' => array(
'href' => array()
)
);
if( isset( $_POST['golf_meta_box_times'] ) )
update_post_meta( $post_id, 'golf_meta_box_times', wp_kses( $_POST['golf_meta_box_times'], $allowed ) );
if( isset( $_POST['golf_meta_box_prices'] ) )
update_post_meta( $post_id, 'golf_meta_box_prices', wp_kses( $_POST['golf_meta_box_prices'], $allowed ) );
}
?>
If anyone has a clue how to make this save it would be a great help!
I am also having issues making the data display - but I can only assume thats where it isnt actually saving haha!
Cheers
functions.php cannot output HTML as far as i know.
wrap your html in a string and return it, your file might be returning errors.
Your add_meta_box code seems to be correct, the condition might not be met, are you sure you are sending data over get?