I hope someone can kindly help with our Woocommerce problem.
I've been stuck looking for examples on how to display an ACF (Advanced Customs Field) field on the Orders Details Page. The difference with my query to others is that the ACF field is set against user information. So in the ACF Field group, I have set "User Role" "is equal" to "All". This works fine and the field can be seen when viewing USERS in the backend. Via the ACF plugin, it will save data against the user.
The field label is "Credit Account Status", and field name is "credit_account_status". Its a checkbox field with 3 options:
Active - No credit given
Active - Credit OK
ON STOP - credit removed; see Accounts Dept.
We want to call up this field when viewing orders on the Order Details page - maybe underneath the shipping address section at the top of the order page. We want this as a visual to prevent us raising new orders manually for someone who hasnt paid their bills on time!
Can anyone help please?
I previously tried to edit the below code, but my programming is very poor - this code seems to bring in data from Order meta, not USER meta.
/**
Display field value on the admin order edit page..
PHP Custom Feild Value
*/
add_action( 'woocommerce_admin_order_data_after_billing_address', 'my_custom_checkout_field_display_admin_order_meta', 10, 1 );
function my_custom_checkout_field_display_admin_order_meta($order){
echo ''.__('Store Location').': ' . get_post_meta( $order->id, 'My Field', true ) . '';
}
Best wishes, Craig
Related
I use WordPress Meta Box for the custom post type
how to appear in the home, archive, recent posts plugins, and other pages
You mean you want to show meta box's value of custom post type in front end. You can show those on anywhere. You just need to know two things the id of Post and the meta_key.
Following function can get you the values of the meta of any post.
get_post_meta( $post_id, 'meta_key', true );
The meta key is the key which is identifier of meta field.
You simply echo those values wherever you want to show them up.
I am using admin columns together with ACF (advanced custom fields)
in the backend I created a field in ACF for just some text, now with admin columns I made this field viewable in the backend for me to add some text that I want .
Now I want to display this text in the my-account page on the frontend.
now I got this far that i added the snippet code to the account page and that works .
But it's only displaying the DEFAULT value I have filled in in ACF and not the value I have entered in the admin custom column backend.
so to clarify even more in my users backend page i give the user a string of text.
That text needs to be displayed in the frontend on the users account
So all users should have a different string of text. The text I can add using admin columns
thats no problem but its only displaying (echo,printing) this text that I have filled in there to the woocommerce account page is not working.
Again I only get the default result text from ACF there not the text I had put in.
For getting default message the code that I use now is:
<?php echo the_field('ethwallet'); ?>
This is giving me the default message right now. not the result that I entered in the backend.
I realize this is an older question, but I wanted to provide an answer as it has been viewed several hundred times.
To retrieve custom meta data (specifically ACF field data) from a User object you need to pass in the current user ID as a second parameter to the get_field or the_field function.
Like so:
<?php echo get_field( 'ethwallet', 'user_' . get_current_user_id() ); ?>
The way it works is that ACF needs the second parameter formatted as user_X, where X is the actual ID of the user (1, 347, whatever). So we concatenate the string part ('user_') with the actual ID of the logged in user and that forms the full parameter to pass to the_field() or get_field().
P.S. It's a minor detail, but in this case echo the_field(); is redundant because the_field() echoes its values by default. You could likely omit the echo or do echo get_field();
I’m building a news aggregator site where I fetch news from a couple of different news sources that converts into Posts. I want my registered users to have the possibility to choose which news sources (Post Categories) they want to see in their feed on my website (not BuddyPress own Activity Feed, but the feed where I list all mixed news posts from different sources).
Is this possible with a custom field or something? So that when the user edits their profile, they can tick the box next to the source they want to add/delete form their feed.
An example of what I want each user to be able to have the freedom to do:
“Select which news sources (Post Categories) you want to read from:”
[ ] USA Today
[ ] The Guardian
[✓] The New Yorker
The specific user above should now only see news from The New Yorker in the news feed.
How would you guys accomplish a solution like this with BuddyPress?
Update
Clarification:
Emma logs onto her account (via BuddyPress plugin) and goes to her Account Settings. In the Account Settings page, I want to list a couple of Checkboxes with news sources. If Emma selects two of the Checkboxes (i.e. The Guardian & USA Today), then Emma wants the WP_Query to only select posts from these Post Categories (which is the different newspapers).
1. How should I create these fields using Advanced Custom Fields and present them on the Profile Settings page?
2. How should I take the values selected from the Advanced Custom Fields in Profile Settings, and filter the WP_Query (which fetches all posts) by Post Category?
Try the Advanced Custom Fields plugin.
http://www.advancedcustomfields.com/
You can use the Taxonomy field type, and use this to get the selected values.
http://www.advancedcustomfields.com/resources/code-examples/#working-with array values
$values = get_field('field_name');
if($values)
{
echo '<ul>';
foreach($values as $value)
{
echo '<li>' . $value . '</li>';
}
echo '</ul>';
}
Then just use a custom query and filter by the category IDs.
https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
$query = new WP_Query( 'cat=2,6,17,38' );
I have made this work, take the input on selection of categories and save the ids of selected categories in custom table and query saved ids ..
I have created a edit link on my wordpress where subscribers can edit their posts. When they click this it takes them back to the admin portal to edit post. I want to make sure they can't see the categories widget on the right side how do I remove that from a user seeing this?
<?php edit_post_link(__("Edit Post"), ''); ?>
I ahve this un the function.php file but need to know how to make it just for subscribers.
function wpse60590_remove_metaboxes() { if() remove_meta_box( 'categorydiv' , 'post' , 'normal' ); remove_meta_box( 'tagsdiv-post_tag' , 'post' , 'normal' ); } add_action( 'admin_menu' , 'wpse60590_remove_metaboxes' );
You need to modify the capabilities of these users' role to prevent them from working with categories. The capability you need to disable for their role should be "manage_categories".
Just make sure all of the users you wish to limit are in the same role (e.g. "Contributor" or something).
In my experience the easiest way to manage capabilities for roles is the Members Plugin.
Once installed, go to Users -> Roles -> Select the role you wish to change. Find "manage_categories", uncheck it, and save.
If you are using a custom post type, we may have to add some settings where you register the taxonomy to specify the ability to assign a category to a post.
I have try to get answer from Wordpress Answer but instead of getting answer I earn Thmbleweed badge. :( anyways so I am trying here and hopping solution.
My new website going to have multiple author. All I need to do with that some specific system where Admin can add banner to the specific author's post.
Fore example xxx banner will only display on xyz author's post and not on any other author post. Which will have auto expiry system, it will automatically invisible when it reach to defined date by admin. All these systems will be under admin control only.
I am not php guy but can play with wordpress codes a bit. So I need really great help to work this out. I also won't mind to give full credit on my website credit display for this system.
Create a table with fields:id, authorid, banner_content, expiry_date.
To fill in the table with specific details of authorid,
banner_content, expiry_date create a simple form or directly enter in
the database.
After your table is created and is filled with details
HERE IS THE COMPLETE CODE TO DISPLAY THE BANNER
<?php
$getid = $posts[0]->post_author; //No need to change this
$sql= "SELECT * FROM bannertable wbanner WHERE author_id = $getid AND expiry_date>CURDATE();"; //change the table name 'bannertable' and field names 'author_id' and 'expiry_date' to your own
$banner_con=$wpdb->get_results($sql);
echo "<div class='banner'>";
foreach ( $banner_con as $content )
{
echo $content->banner; //change field name 'banner'.
}
echo "</div>
?>
Make sure to enter the above code inside the loop of your theme.