Adding a Advanced Custom Field to Woocommerce users My Account Page - wordpress

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();

Related

How to add custom fields in invoice and wordpress backend?

I am working on a wocommerce website, and i want to display a tax that will be custom calculated eg: (weight0.660+price=taxquantity) i am using this formula for custom fields calculation. now i want to display the calculated output on user invoice when user checks out. please help me with this
I am using ACF pro plugin to create custom fields and add custom formula.
You need to find the template for the invoice and add
<?php echo get_field('fieldname', $id); ?>
fieldname will be the name of the ACF field and $id will need to be the post id for wherever the field is

CFDB plugin : Preventing Duplicate Submissions from CF7

I have a form where user add his email address, I’m trying to prevent users to enter there email many times. I use "contact form to database plugin" to save email address and export them to excel. while searching on internet I found this solution (link below) but I can’t get it work can you help me please :
https://cfdbplugin.com/?page_id=904
Thanks
I found the solution,
in the line where you put the name of the form you should put the title of the form (line bellow ) :
$formName = 'email_form'; // Change to name of the form containing this field
so, for exemple if we have created with the contact form 7 a form here is the shortcode that we will have :
<?php echo do_shortcode( '[contact-form-7 id="69" title="Email_form" html_name="my_form"]' ); ?>
what I did is I put the value of html_name in the script of CFDB but when I changed to the value of title it works

WordPress Page Templates for Custom Post Type

I have a custom post type, "Store Pages" for instance, which is an almost identical duplicate of the default Wordpress "Page" post type.
Like the "page" post type, I would like to create page templates (not post-type templates) and be able to select them from the "Template" drop-down within the "Page attributes" box in the page editor.
I have created several templates, but the drop-down menu does not appear; I am assuming this is because a custom post types does not allow support for this.
Is there a way I can create page templates for a custom post type without using "single-{post-type-name}.php" and having a dozen queries to load up different template files?
I have double checked the comments for the templates are correct as they appear when I create a new page (post type, "Page").
Help would be greatly appreciated.
starting 4.7 you can use the new feature described here https://make.wordpress.org/core/2016/11/03/post-type-templates-in-4-7/
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
// … your code here
If I understood correctly you want a Select template dropdown for your custom post type.
You can do this easily through Advanced Custom Fields, here's a quick guide how to get through.
After installing the plugin you can access the Custom Field section, if you open it and click Add new it bring you to the field editor. Name it whatever you want, it's just for administrative display.
On Field type choose "Select", this will allow you to construct a select box on your backend, keep in mind the value of "Field name" you will need this later on the code.
Scrolling down you can add the values of the select box in the following format: "key value : Textual label" just assume for now you want 2 templates, one for audio posts and one for video posts.
If you keep scrolling down you can see the display rule for this field group, now you will have "post" and "page" by default, when you add different content types you will have the additional content types here to select, just go ahead and pick yours.
And, ta-da. If you go on the custom content type edit window you will find your new fresh select box here waiting for you.
The code integration now is very simple, just go onto your single-{post-type-name}.php template and pull the custom field data into your loop. Then you can use this to use get_template_part() to pull your custom templates.
<?php $template_type = get_field('template'); // This must match with the field name value ?>
<?php if (isset($template_type) && !empty($template_type)): ?>
<?php get_template_part( 'store', $template_type ); ?>
<?php else: ?>
// You should have a fallback for the all the existing posts without template set or if you create a new post without a template.
<?php endif; ?>
In this specific example the pulled template files will be in the format of store-{key-value-of-the-selectbox}.php, of course you can readapt that for you best convenience.

Dropdown of existing posts in a metabox

I want to have ability to choose for each page what post should appear in a sidebar, from multiple posts type. So I understand that I need a meta box with a dropdown list of all posts, but I don't know how to build this in functions.
I only found this solution which is quite similar to what I want, but this doesn't help me to much, because I can only choose from a single post type and display only in post pages.
There is a free plugin that will solve all of your woes. It's called ACF or Advanced Custom Fields. It has the ability to add a list of posts to a field and attach that field to pages. Here's how you'd do it:
First install the plugin and navigate to the custom fields screen. Setup your field exactly like this:
Then in the options below that section you need to select these options:
That will tell ACF to put the field only on pages. After you have set that up you will get a little sidebar block like this:
You can then select each post for the page and it will return that object on the frontend. You do need to use a little code to get the frontend to spit out the posts you need. Here is the code to get a frontend option from ACF. Inside of the sidebar.php file you need to add this code:
global $post; // Get the global post object
$sidebar_posts = get_field('posts', $post->ID); // Get the field using the post ID
foreach($sidebar_posts as $sidebar_post){ // Loop through posts
echo $sidebar_post->post_title; // Echo the post title
}
This will simply loop through the posts you select and echo out the title. You can do more with this by adding some other Wordpress post functions using setup_postdata(). This will allow you to do things like the_title() and the_content().
Hope this helps!

Author Post Specific Banners with Admin Control and Expiry system

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.

Resources