Woocommerce I am looking for billing address and order-received email hooks - wordpress

I have to make two customization on my woocommerce site.
I need to know two main hooks. Someone out there please help me out!
Show custom field values to billing address on order-received page.(I added custom fields on checkout page.)
Need to include these values to customers' order-received email, too.
Thanks for stopping by.

To show custom field in order-received page you have to use
woocommerce_thankyou hook.
Here is the code:
// define the woocommerce_thankyou callback
function action_woocommerce_thankyou($order_id)
{
$my_custom_field = get_post_meta($order_id, '_billing_my_field', TRUE);
}
// add the action
add_action('woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1);
UPDARED This section after post author comment
To add custom billing fields in WooCommerce email you have to use
woocommerce_email_customer_details hook; this will be displayed just
before the customer details.
Here is the code:
add_filter('woocommerce_email_customer_details', 'custom_woocommerce_email_order_meta_fields', 10, 3);
function custom_woocommerce_email_order_meta_fields($order, $sent_to_admin, $plain_text)
{
$_billing_my_field = get_post_meta($order->id, '_billing_my_field', true);
if ($plain_text)
{
echo 'My field is ' . $_billing_my_field;
}
else
{
echo '<p>My field is ' . $_billing_my_field . '</p>';
}
}
All code goes in function.php file of your active child theme (or theme) or also in any plugin file.
Please Note:
I have assuming that you have added a custom billing fields as $fields['billing']['billing_my_field'] using woocommerce_checkout_fields hook.
All the codes are tested and fully functional.

Related

Customize woocommerce order tracking page

in the default order tracking page for wooocommerce there are two fields { ordreid and email }
.
I want to make email field unrequired
I tried with this code in function.php file but it wasn't successful :(
add_filter( 'woocommerce-order-tracking', 'ts_unrequire_wc_email_field');
function ts_unrequire_wc_email_field( $fields ) {
$fields['order_email']['required'] = false;
return $fields;
}
any help will be useful .. and i hope that you are all safe during the breakout of covid-19 <3**

execute do_shortcode in functions.php

I'm trying to run a do_shortcode in functions.php with no luck
I'm using Types plugin http://wp-types.com/ for creating custom post types and custom fields.
What I'm trying do is adding a custom column in admin for view all custom posts that displays a thumbnail from a custom field.
This is what I got so far, but it seems that the shortcode doesn't work inside functions.php
// add a column for custom post type (products)
add_filter('manage_product_posts_columns', 'add_thumbnail_column');
add_action('manage_product_posts_custom_column', 'add_thumbnail_content', 10, 2);
function add_thumbnail_column($defaults)
{
$newSlice = array('thumbnail' => 'Image preview');
$counter = 2;
$array_head = array_slice($defaults,0,$counter);
$array_tail = array_slice($defaults,$counter);
$defaults = array_merge($array_head, $newSlice);
$defaults = array_merge($defaults, $array_tail);
return $defaults;
}
function add_thumbnail_content($column_name, $post_ID)
{
// this one works when putting into post content
echo do_shortcode('[types field="square-picture" id="' . $post_ID . '" size="thumbnail"]' . '[/types]');
}
Can anyone help please?
In the Wordpress notes for the function it says
"If there are no shortcode tags defined, then the content will be
returned without any filtering. This might cause issues if a plugin is
disabled as its shortcode will still show up in the post or content."
Types may be conditionally declaring their short code only when you are on the frontend. What may be happening is that, in the admin, the short code is not defined and you are simply getting a false return. While on the frontend, the shortcode is defined and you get the results you intended.

How do you make a Wordpress plugin have "per post" options?

I'm building a Wordpress blog that requires a custom slideshow system with an admin panel on each post admin page (sort of like how Yoast's SEO plugin has options on each page).
How would I make the admin options appear on the post admin page?
Thanks,
Charlie
You are not providing much detail about your project but you probably want to make some meta_boxes and save the data to as custom fields.
Here is a truncated example culled from something I put together for a question at wordpress.stackexchange. The details of some of the functions are not important for your question here but it illustrates the general 'how'. Follow the link for working but sincerely beta code.
// author checkboxes
add_action( 'add_meta_boxes', 'assisting_editor' );
function assisting_editor() {
add_meta_box(
'assisting_editor', // id, used as the html id att
__( 'Editorial Tasks' ), // meta box title
'editor_tasks', // callback function, spits out the content
'post', // post type or page. This adds to posts only
'side', // context, where on the screen
'low' // priority, where should this go in the context
);
}
// this is the callback that creates the meta box content
function editor_tasks( $post ) {
// function details skipped; follow the link
}
// to save the data
add_action( 'save_post', 'save_metadata');
// callback for the save hook ^^
function save_metadata($postid) {
// function details skipped; follow the link
}

is there a way (plugin) to insert html/css/images ect automatically into every wordpress post?

is there a way (plugin) to insert html/css/images ect.. automatically into every wordpress post? most of my posts are going to be very similar so is there a plugin that will automatically insert the pre written html/css/ ect in every post as opposed to me entering it manually every time.
Thank you in advance ;-)
You can write your own simple function for this, see my example below:
add_filter( 'default_content', 'my_editor_content' );
function my_editor_content( $content ) {
global $post_type;
if( $post_type == 'post') { /* Or your custom post type, pages etc. */
$content = 'Your custom HTML/CSS content here';
}
return $content;
}
Place this in functions.php and it will be the default content of every new post/page/custom post type you create.
For a list of available post types, please refer to the Codex
You could use a plugin such as Ad injection, it will allow you to do what you need without having to alter / amend / ad any code to the templates or files

display custom fields automatically when a custom post type is displayed

I am trying to automatically display all the custom fields of a custom post type alongside it's title and content.(Not in admin but on my actual site)
I need to be able to do this with an action hook or filter, rather than creating a template.
After scouring the web I was able to find the 'publish_{custom_post_type_name}' hook:
function my_cool_hook() {
echo get_post_meta($post->ID, 'my-custom-field-name', true);
}
add_action( 'publish_past_symposia', 'my_cool_hook' );
but it doesn't seem to do anything when I view my published custom post type on my site. Any ideas?
add_action( 'publish_past_symposia', 'my_cool_hook' );
This hook triggered only if PUBLISH post type.
YOu need to trigger the hook on web part - so...
add_filter('the_content', 'my_cool_hook');
function my_cool_hook($content){
return $content.get_post_meta(get_the_id(), 'my-custom-field-name', true);
}
now the content body filtred and your string from custom fields added.

Resources