Add Advanced Custom Field to Woocommerce My Account Page - wordpress

I'm trying to add a ACF to the woocommerce front end 'My Account' page.
I've created the field, called it 'vat_number' and managed to add it to the User Edit Screen on the backend of the website.
I'm trying to add this field to the Edit Address front end screen on Woocommerce.
I've tried adding the following to the 'My-address.php' template, but it doesn't work
<?php the_field('vat_number', $user_id); ?>
But it's not working, does anyone know where i'm going wrong?

Does the $user_id need to be the id of the current logged-in user? If so, you need to get the user ID first.
$user_ID = get_current_user_id();
the_field('vat_number', $user_ID);

Related

Elementor - Add Buy now button dynamically next to add to cart

I am attempting to add a buy now button in elementor on custom single product page so there are two buttons:
add to cart
buy now (which will redirect to checkout & skip cart)
I still want add to cart to function as usual.
How can I achieve this? Many thanks.
After a little research I came up with a solution to this problem
using PHP code snippet
<?php
$product = wc_get_product();
$id = $product->get_id();
echo home_url('/checkout/?add-to-cart='.$product->id);
?>
then i linked the button to this code using shortcode

Can we replicate ACF functionality in our theme?

Hi i want to add advance custom fields in my wordpress theme. I don't need editor functionality but to provide the users the facility to enter the values to view in the frontend.
basically i want to add the custom fields in my theme just like ACF but i don't want to use the plugin. Is there anything anyone can help me out with this please do.
I'm using ACF plugin right now to add custom fields in my theme.
For example I'm getting the designation from user in the admin panel and our team members custom post type. and showing it on the home page by using this code.
<p><span class="fa fa-user-circle"></span> Designation</strong>:<?php echo the_field( 'designation' ); ?> </p>
I don't want to use ACF plugin to perform this task. I know about the wordpress custom field. The problem with wordpress custom field is I've to select the key every time when I create a post. Here's a sample of what I'm trying to do. I want to add the this in my add new post.
Right now I've to select the key value whenever a new post is created. I want something similar to the image attached in my add new post. Thanks.
You can use native WordPress function(s) to do the same thing. Of course, you lose the extensive ACF features and slick ACF admin panels.
Instead of using ACF's get_field(), you can use get_post_meta(get_the_ID(), 'field', true);
List all items in the meta field 'appartments' like so:
$meta_name = 'appartments';
$fields = get_post_meta( $post->ID, $meta_name, true );
foreach ( $fields as $fieldValue )
{
echo $fieldValue . ' ';
}

hide popup maker plugin link from wordpress

I installed pop up maker and capabilities plugin in wordpress for my website. I want to create one user who is not able to see the link for pop up maker. I tried with adding user with some capability but I am not able to hide pop up maker link.
How can I achieve this? Do I need to use another capability plugin?
You can use the remove_menu_page() function called via the admin_menu action hook. If you just want to remove the link for a single user, check the current user's ID first with wp_get_current_user().
function remove_admin_menu_item_for_user() {
$user = wp_get_current_user();
// Check to see if the current user's ID is the one we want to remove the page for
if ( $user->ID == ??? ){
// Use the $menu_slug for the page you want to remove
remove_menu_page( $menu_slug );
}
}
add_action( 'admin_menu', 'remove_admin_menu_item_for_user' );
If you would prefer to use a plugin Admin Menu Editor should work as well, though you may need the Pro version.

WordPress hiding categories view from edit posts

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.

Wordpress user dashboard custom left menu example code help needed

I need help to show the left menu item on other role users dashboard. I am using the code at plugin to add the custom admin menu items .
add_action('admin_menu', 'wp_hotlel_admin_menu');
function wp_hotlel_admin_menu() {
add_menu_page('Page Title', 'Menu Title', 10,'unique-slug','ChainForm_page');
function ChainForm_page() {
echo "test";
}
The menu is being displayed and working at admin dashboard. But not being displayed at other users dashboard. I am being logged in through Wordpress basic users login section.
I have added the line below,
global $wp_roles;
$wp_roles->add_cap('Subscriber','wp-wall');
Subscriber is my user type. The menu item is not being displayed still at general users custom menu.
Please help me to fix this.
Thanks in advance.
The add_cap has been deprecated since version 2.8 I believe. You could use something like:
<?php
if( current_user_can( 'edit-posts' ) ){
//YOUR CODE HERE
}
?>
See the Codex Pages for Roles and Capabilities:
http://codex.wordpress.org/Roles_and_Capabilities
And a simplified version:
http://web-profile.com.ua/wordpress/dev/user-capabilities/
Your value 10 (the third argument) should be replaced with a capability (e.g. 'edit_pages'). User levels are deprecated. Here is a list of all available capabilities and their associated roles.

Resources