Code Snippets for MyListing

I thought it might frustrate users from signing in. There might be a better way via php (backend) but exposing the email on the front end might be used for some other features.

If you want to keep updating your theme, duplicate these files into your child theme using the same folder structure (/sections/header.php and /templates/add-listing/submit-form.php).

Add the following line into line 90 on the header.php :

<a class="user-profile-name" data-email="<?php echo esc_attr( $current_user->user_email ) ?>" href="#" type="button" id="user-dropdown-menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">

Add this after line 16 in submit-form.php :

<script>
jQuery(function(){
	var $email = jQuery('#job_email');

	if($email.val() == ''){
		$email.val(jQuery('.user-profile-name').attr('data-email'));
	}
});
</script>
Submitted by: Michael Shpigelman

Require a log in to view a listing type in this case its properties.

1. Go to /wp-admin/options-permalink.php and replace “listing” by %listing_type% so your URL will contain the listing type instead of doing a query on the DB to get the type of the listing.

2. Add the following code into your functions.php file.

 

add_action( 'wp_loaded', 'redirect_to_login' );
function redirect_to_login(){
    session_start();

    if(strpos($_SERVER['REQUEST_URI'], "properties") !== false && !is_user_logged_in()):
        $_SESSION['login_error_page'] = $_SERVER['REQUEST_URI'];
        wp_redirect(get_permalink(203));
        exit();
    endif;

    if($_SESSION['login_error_page']){
        wc_add_notice( __("Please register or login first to view properties.", 'my-listing'), 'error');
        echo "
        <script>
            window.onload = function() {
                jQuery(function(){
                    jQuery('.sign-in-form input[name="_wp_http_referer"]').val('" . $_SESSION['login_error_page'] . "');
                })
            }
        </script>";
        unset($_SESSION['login_error_page']);
    }
}
Submitted by: Michael Shpigelman

Add this to the Theme Tools Under Advanced or Under Appearance > Customizer

/* ML - HIDE SIGN IN AND REGISTER FROM NAV MENU */
.header .user-area.signin-area,
.header .mob-sign-in {
  display: none !important;
}
Submitted by: Donald McGuinn

Add this code to your child theme functions.php file. Nothing else is required. Clear cache if you don’t see it working.

// REGISTRATION FORM FIELDS
// https://businessbloomer.com/woocommerce-add-first-last-name-account-register-form/
// ============================================================================= 
add_action( 'woocommerce_register_form_start', 'bbloomer_add_name_woo_account_registration' );
  
function bbloomer_add_name_woo_account_registration() {
    ?>
  
    <p class="form-row form-row-first">
    <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />
    </p>
  
    <p class="form-row form-row-last">
    <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />
    </p>
  
    <div class="clear"></div>
  
    <?php
}
  
///////////////////////////////
// 2. VALIDATE FIELDS
  
add_filter( 'woocommerce_registration_errors', 'bbloomer_validate_name_fields', 10, 3 );
  
function bbloomer_validate_name_fields( $errors, $username, $email ) {
    if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {
        $errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );
    }
    if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {
        $errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );
    }
    return $errors;
}
  
///////////////////////////////
// 3. SAVE FIELDS
  
add_action( 'woocommerce_created_customer', 'bbloomer_save_name_fields' );
  
function bbloomer_save_name_fields( $customer_id ) {
    if ( isset( $_POST['billing_first_name'] ) ) {
        update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );
        update_user_meta( $customer_id, 'first_name', sanitize_text_field($_POST['billing_first_name']) );
    }
    if ( isset( $_POST['billing_last_name'] ) ) {
        update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );
        update_user_meta( $customer_id, 'last_name', sanitize_text_field($_POST['billing_last_name']) );
    }
  
}
Submitted by: Donald McGuinn

Add this code to your child theme functions.php file then use the class selectors below:

.loggedin

.loggedout

// LOGGED IN AND OUT BODY CLASS
// ============================================================================= 
// Add specific CSS class by filter
add_filter('body_class','er_logged_in_filter');
function er_logged_in_filter($classes) {
if( is_user_logged_in() ) {
$classes[] = 'loggedin';
} else {
$classes[] = 'loggedout';
}
// return the $classes array
return $classes;
}
Submitted by: Donald McGuinn

Insert this code into your child theme functions.php file. Then, use the class selector below.

.role-administrator

.role-editor

.role-author

.role-subscriber

.role-customer

// ADD USER ROLE TO BODY CLASS
// ============================================================================= 
if ( is_user_logged_in() ) {
    add_filter('body_class','add_role_to_body');
    add_filter('admin_body_class','add_role_to_body');
}
function add_role_to_body($classes) {
    $current_user = new WP_User(get_current_user_id());
    $user_role = array_shift($current_user->roles);
    if (is_admin()) {
        $classes .= 'role-'. $user_role;
    } else {
        $classes[] = 'role-'. $user_role;
    }
    return $classes;
}
Submitted by: Donald McGuinn

Add this code to Custom Js to enable Listing Carousel to autoplay.

jQuery(document).ready(function($) {
    if ( $('.listing-feed-carousel').length ) {
        $('.listing-feed-carousel').data('owl.carousel').options.autoplay = true;
        $('.listing-feed-carousel').data('owl.carousel').options.autoplayHoverPause = true;
        $('.listing-feed-carousel').data('owl.carousel').options.autoplayTimeout = 2500;
        $('.listing-feed-carousel').data('owl.carousel').refresh();
    }
});
Submitted by: Donald McGuinn

If you need to change the color of your footer to something different as well as the text, check out the snippet below:

.footer{
background-color: black;
}
.footer *{
color: white !important;
}
Submitted by: Donald McGuinn

YOU NEED ELEMENTOR PRO:

  • -Go to Elementor Templates on Dashboard
  • -Create New SAVED TEMPLATE
  • -Make it a section template (not page)
  • -Name it whatever you want
  • -Paste in a shortcode element [listing_qr]
  • -Save it and return to the template page where you see all your templates
  • -Copy the shortcode associated with that template from the right-hand side (you need Elementor Pro)
  • -Take that shortcode and paste it in a shortcode block on the single page settings of the listing type you need it to show on.

Add the code below to your functions.php file.

//LISTING QR CODE GENERATOR
//=========================
function qr_code_generator() {

	$permalink = get_permalink($post->ID);
	echo '<img src="https://api.qrserver.com/v1/create-qr-code/?size=100x100&data='.$permalink.'">';

}
add_shortcode( 'listing_qr', 'qr_code_generator' );
Submitted by: Donald McGuinn

Simply put, this button styles the “X” and circle of the close button on the messages popup.

/*MESSAGES CLOSE BUTTON*/
#ml-messages-modal button.close{
	background: #f94954;
	color: white;
	text-shadow: none;
}

#ml-messages-modal button.close:before{
	opacity: 1;
}
Submitted by: Donald McGuinn

This is an odd one but I needed it so here it is! On this site, for the professionals adding their portfolio items, those are mainly screenshots. While the “center center” position works great for regular images, screenshots, on the other hand, look weird when positioned that way. So this will align the image to the top instead of the center. See before and after below.

/*MESSAGES CLOSE BUTTON*/
#ml-messages-modal button.close{
	background: #f94954;
	color: white;
	text-shadow: none;
}

#ml-messages-modal button.close:before{
	opacity: 1;
}
Submitted by: Donald McGuinn

By default, MyListing hides the ACF options/settings menu. You can re enable this by adding this code to your child theme functions.php file.

//ENABLE ACF OPTIONS
//========================
add_filter( 'acf/settings/show_admin', '__return_true', 50 );
Submitted by: Donald McGuinn

This code hides the ability to switch plans on the listing management under My Listings.

/*HIDE SWITCH PLAN ON LISTING DASHBOARD*/
#job-manager-job-dashboard table ul.job-dashboard-actions li.cts-listing-action-switch{
	display: none !important;
}
Submitted by: Donald McGuinn

This code hies the promote tab on the “listing manager” in the account page.

/*HIDE PROMOTE ON LISTING DASHBOARD*/
#job-manager-job-dashboard table ul.job-dashboard-actions li.cts-listing-action-promote{
	display: none !important;
}
Submitted by: Donald McGuinn

Show navigation arrows indicating there are more quick action tiles for them to view by swiping on their mobile device.

/*QUICK ACTION AND SINGLE LISTING TABS NAVIGATION*/
@media (max-width: 767px){
.profile-header:before{
	font-family: "Font Awesome 5 Free"; 
	font-weight: 900; 
	content: "\f053";
	position: absolute;
		left: 10px;
	top: 20px;
}
	
	.profile-header .profile-menu ul{

	}

.profile-header:after{
	font-family: "Font Awesome 5 Free"; 
	font-weight: 900; 
	content: "\f054";
	position: absolute;
	right: 10px;
	top: 20px;
	}

	.quick-listing-actions ul:after{
		font-family: "Font Awesome 5 Free"; 
	font-weight: 900; 
	content: "\f054";
	position: absolute;
	right: 15px;
	}
	.quick-listing-actions ul:before{
	font-family: "Font Awesome 5 Free"; 
	font-weight: 900; 
	content: "\f053";
	position: absolute;
		left: 15px;
}}
Submitted by: Donald McGuinn