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.
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 have custom post types for which having a 'title' field doesn't really make sense, so the post type has none.
Problem is that when you use a post type in a relationship, the user interface for picking which posts to relate wants to display the title.
In the box where you are choosing posts (clicking them and they move to the right pane), can a field other that 'title' be displayed?
It's doable. I would use a filter hook provided by acf plugin 'acf/fields/relationship/result/name=related_posts'. Take a look at the following code:
add_filter( 'acf/fields/relationship/result/name=related_posts', 'my_custom_title', 10, 2 );
function my_custom_title( $title, $acf_array ) {
// You could remove the $title altogether or you could add something meaningful to it such as time stamp or anything that would make sense!
return $title . "Adding somthing meaningful to the title!";
}
I am trying to customise the Woocommerce myaccount page, in particular the edit address page.
I want to display both the shipping + billing address forms on a single page. Ideally, in a single form with a one save button. I also need to remove a lot of the fields, so that it's a much simpler form of just an address (no name, company, etc).
I have implemented the code found on This Answer. It works nicely in that it shows both forms. However, I cannot remove the fields from the forms. If I try code like this:
add_filter( 'woocommerce_billing_fields' , 'custom_override_billing_fields' );
add_filter( 'woocommerce_shipping_fields' , 'custom_override_shipping_fields' );
function custom_override_billing_fields( $fields ) {
unset($fields['billing_country']);
unset($fields['billing_company']);
unset($fields['billing_first_name']);
unset($fields['billing_last_name']);
unset($fields['billing_phone']);
unset($fields['billing_email']);
return $fields;
}
function custom_override_shipping_fields( $fields ) {
unset($fields['shipping_country']);
unset($fields['shipping_company']);
unset($fields['shipping_first_name']);
unset($fields['shipping_last_name']);
return $fields;
}
It doesn't work, the fields are no longer shown but the form does not save on click... it just redirects to /my-account/edit-address/billing/ - and doesn't save. (the same form shown on this page doesn't save either).
I've also tried:
foreach ( $billing_fields as $key => $field ) :
if($key != 'billing_first_name' && $key != 'billing_last_name') :
woocommerce_form_field( $key, $field, $userMeta[$key][0] );
endif;
endforeach;
This removes the field from displaying, BUT the validation still exists - and any filter code I add to functions using
woocommerce_checkout_fields to remove the validation doesn't seem to affect this form at all.
Is there a way to either:
Remove fields from this form generated by woocommerce_form_field including the validation?
Create a custom form that allows me to set the input fields manually in the code, and update any fields that are there, ignoring the validation from Woocommerce completely?
This should work 100%. You need to state whether the fields you are removing is from billing or shipping and this is done by adding the ['billing'] or ['shipping'], whichever it is.
After this, adding the function directly to woocommerce_checkout_fields will apply both for billing and shipping.
For phone and company fields you can disable it in admin panel itself, do it.
Edit: And yes, all validation that was involved with the fields in the past will be removed. You can then apply any validation you need.
add_filter( 'woocommerce_checkout_fields' , 'brandimagemarketer_remove_billing_fields_checkout' );
function brandimagemarketer_remove_billing_fields_checkout( $fields ) {
unset($fields['billing']['billing_country']);
unset($fields['billing']['billing_first_name']);
unset($fields['billing']['billing_last_name']);
unset($fields['billing']['billing_email']);
unset($fields['shipping']['shipping_country']);
unset($fields['shipping']['shipping_first_name']);
unset($fields['shipping']['shipping_last_name']);
unset($fields['shipping']['shipping_email']);
return $fields;
}
my customer wants the shop "customers" (which are resellers in a b2b-shop) to be able to order every product for a variable number of stores for which he is responsible. If, for example, he has 3 stores, he wants
Store 1: 10 (qty)
Store 2: 10
Store 3: 5
and the regular WC amount field with +/- next to the big "add to cart" button should automatically update (to 25 in this case).
So I added some text fields to the single product view, below the thumbnails with this:
add_action( 'woocommerce_product_thumbnails', 'store_selector' );
function store_selector() {
$stores = get_stores();
echo '<div itemprop="store-selector" class="store-selector" style="font-size: 14px;">';
echo '<div class="product-border fusion-separator sep-"></div>';
echo '<input type='text' class='amount_per_store' name='amount_ps_".$store_id."' id='amount_ps_".$store_id."'>"'
echo '<br></div>';
}
So now I can loop through the fields, add them all up, and write the result to the big add-to-cart-field with simple jQuery. Works well.
But the Problem is: I don't seem able to access my custom fields later! All I can see is the "25", but not the order numbers for single stores. Of course not...WooCommerce does not really know my custom fields!
Maybe I should do something like this:
woocommerce_form_field( 'my_field_name', array(
'type' => 'text',
'class' => array('amount_per_store'),
'label' => __('Store '.$store_id),
'placeholder' => __(''),
), $checkout->get_value( 'my_field_name' ));
I foud this here:
https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/
...it's an example of how to add custom fields to other places.
I am a bit stuck at the moment because I don't know how to add custom fields for products the right way!
-A customer should be able to correct / edit his order and change the value of the custom fields when he goes back.
-Values should be carried through the ordering process, appear on the order confirmation page, in the order emails and also in the order details in the backend.
Any help is greatly acknowledged!
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.