Thursday 17 August 2017

Wordpress Hook Add ADMIN CSS

Here is the Wordpress Hook  Add ADMIN CSS:

/* --- THEME: ADMIN CSS --- */
add_action('admin_head', 'headercss');
function headercss()
{
echo '
<style>
li#menu-posts-slide {
  display: none;
}
li#menu-links {
  display: none;
}

</style>';}

Woocommerce Login Redirect Hook

// Here is the redirect admins to dashboard

function wc_custom_user_redirect( $redirect, $user ) {
$role = $user->roles[0];
$dashboard = admin_url();
$myaccount = get_permalink( wc_get_page_id( 'myaccount' ) );
if( $role == 'administrator' ) {
$redirect = $dashboard;
} elseif ( $role == 'shop-manager' ) {
$redirect = $dashboard;
} elseif ( $role == 'editor' ) {
$redirect = $dashboard;
} elseif ( $role == 'author' ) {
$redirect = $dashboard;
} elseif ( $role == 'customer' || $role == 'subscriber' ) {
$redirect = $myaccount;
} else {
$redirect = $myaccount;
}
return $redirect;
}
add_filter( 'woocommerce_login_redirect', 'wc_custom_user_redirect', 10, 2 );

Wordpress Hook To Add Specific Script to Specific Page Template

Here is the Wordpress Hook To Add Specific Script to Specific Page Template:


function customJS()
{
if (is_page_template('page-template-cart-checkout.php')||is_page_template('page-template-my-account.php')):
include ("woocommerce-states.php");

endif;
}
add_action('wp_enqueue_scripts', 'customJS');

Jquery Important Methods

Here are the some Jquery important methods and functions:

1. Add html to div with jquery:

$("#divID").html("Html Added!!");

2. Disable Input Field:

$("#inputID").attr('disabled', 'disabled');

3. Email Pattern:

var pattern = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;

4. Add Class To Div:

$("#divID").addClass("Added");

5. Input Field Empty or not:

$("input").val().length == 0;

Google Map Filter Api Example

Here is Google Map Filter Api Example: