PHP - Display text if checkbox selected - php

I am using the user registration plugin (https://wpeverest.com/wordpress-plugins/user-registration/). When a user signs up, there is an option to ask them if they're 'new team' or not. If they check 'new team' I then want to display text when they are signed in.
I have tried the following:-
<?php
$user = wp_get_current_user();
if ( in_array( 'msp_team', (array) $user->user_registration_msp_team ) ) {
echo ('TESTTTT');
}
?>
But the text is not displaying. Could someone please advise what I am doing wrong here?
Thank you!

Managed to sort this with the following code:-
<?php if ( get_field( 'user_registration_msp_team', 'user_' . $current_user->ID ) ): ?>
FIELD CODE....
<?php else: ?>
OTHER CONTENT IF FIELD IS EMPTY
<?php endif; ?>

Related

advanced custom fields true/false only works in front-page.?? not in innerpages why?

I have an ACF true or false based if the condition to show a section based on the mentioned code. it works correctly on the front page/homepage of WordPress. but it doesn't work in the inner pages, not getting the values of the field and I use this code in footer templates.
its a WordPress site with the latest version. and the code is in the footer template
<?php
$show_company_info = get_field( "show_company_info", get_the_ID() );
if($show_company_info ):
?>
<section class="company">
<div class="container">
<?php if ( is_active_sidebar( 'company-info-widget' ) ) : ?>
<?php dynamic_sidebar( 'company-info-widget' ); ?>
<?php endif; ?>
</div>
</section>
<?php endif; ?>
if we checked the ACF true/fields condition in any page it will show the section otherwise not. but it actually works in homepage only
Assuming that you have created a field in a Home Page.
So, to retrieve the home page field you need to do like this :
$frontpage_id = get_option( 'page_on_front' );
$show_company_info = get_field( "show_company_info", $frontpage_id );
if ( $show_company_info ) {
//Your code
}

php unless wordpress user role = "subscriber" display this html code

I need to display HTML code to all user roles except "subscriber" in wordpress.
Here is code that I can't get working.
<?php
$current_user = wp_get_current_user();
?>
<?php if ( $current_user->role == 'subscriber' ) : ?>
<span>here is my html</span>
<?php endif; ?>
PS
I'm not that good with php as you can tell.
Solved! I used following code that gives desired functionality:
<?php if ( $this->current_user_can_edit_posts ) : ?>
<span>my html</span>
<?php endif; ?>
For others, you might need to change "$this" part. So you can retrieve current_user. Maybe someone can still post an answer for them.
Tried and tested code that works. Let me know if it works for you too! :)
<?php
$current_user = wp_get_current_user();
if ( ! in_array( 'subscriber', (array) $current_user->roles ) ) {
?>
<span>here is my html</span>
<?php
}
?>

Show ACF in customer account dashboard - Woocommerce

I would like to show a custom welcome message for each of my registered shop customers. Something like "Welcome CUSTOMERNAME! You have been with us for one year now. To say thanks, we are giving you a discount on everything in our shop of 10%."
I have created a custom field welcome_message with the plugin Advanced Custom Fields and would like to show the value of it in the account dashboard of my customers at frontend.
At the backend, I am showing the textarea at the user profile page and I am adding the field with this code:
$message = get_field( 'welcome_message' );
echo esc_attr( $message );
This code is placed here: /wp-content/themes/flatsome-child/woocommerce/myaccount/dashboard.php
But somehow the value is not coming up. I have also tried it with simply the_field('welcome_message'); or to add [acf field="{$welcome_message}"] at the account page in WordPress but that didn't work either. Somehow the value is not coming through.
I hope someone could help me out a litte.
Thanks in advance.
Best regards
It's necessary that get_field function is connected to user.
Eg:
<?php
$variable = get_field('field_name', 'user_1');
?>
In case of repeater field:
<?php if( have_rows('repeater', 'user_1') ): ?>
<ul>
<?php while( have_rows('repeater', 'user_1') ): the_row(); ?>
<li><?php the_sub_field('title'); ?></li>
<?php endwhile; ?>
</ul>
<?php endif; ?>

Wordpress if(post_name === nameOfPost) not working

I am trying to display specific text at the bottom of a menu but I only want this text to show if I am looking at a certain menu. This is the code I have:
<?php get_post_type( $post ) ?>
<?php if ( $post->post_name === 'belden-village' ) : ?>
<?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank You</p>"; ?>
<?php endif ?>
This code works in staging but as soon as we moved the site live it no longer displays the text when it is supposed to. I am calling it by the "slug" and the slug is the same in both staging and live site. Any ideas why this has suddenly stopped working? This is my first experience taking a site live so any help would be greatly appreciated. Thanks.
Why not use the is_single() function?
<?php get_post_type( $post ) ?>
<?php if ( is_single( 'belden-village') ) : ?>
<?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank
You</p>"; ?>
<?php endif ?>
If you are looking for a page instead of a post you can use the is_page() function instead:
<?php get_post_type( $post ) ?>
<?php if ( is_page( 'belden-village') ) : ?>
<?php echo "<p>*For all groups of 8 or more, an 18% gratuity will be included on your guest check. Thank
You</p>"; ?>
<?php endif ?>

Advanced Custom Fields checkbox display value

I'm struggling with ACF checkboxes, I'm trying to check the array to see if 'car' has been ticked:
if( in_array( 'car', the_sub_field('tyres_available') ) )
{
echo 'some html';
}
'car' is one of the checkbox options. If it's ticked I want to echo out some html. At the moment it's outputting the whole array for every checkbox that has been ticked in the field 'tyres_available'.
Any ideas where am I going wrong?
Thanks
Sorted. It's get_sub_field, not the_sub_field:
<?php $tyreServices = get_sub_field('tyres_available'); ?>
<?php if(in_array("car", $tyreServices )){ ?>
Some html
<?php } ?>

Categories