Category: Wordpress

Get all user meta data by user email address in WordPress

Here is a quick snippet to get all user meta data by email address in WordPress. The following code will print all user meta data for given email address in wordpress.

$user = get_user_by( 'email', $email_address );
$user_id=$user->ID;
$all_meta_for_user = get_user_meta( $user_id );
print_r( $all_meta_for_user );

Have any doubt, then comment here!

Remove wocommerce coupon field from woocommerce checkout page

Here is a quick snippet to remove woocommerce coupon field from woocommerce checkout page. When you enable the use of coupons, woocommerce adds the apply coupon form in cart and checkout page. For our customization want to remove woocommerce coupon field from checkout page then place the following snippet in functions.php within your theme folder!.

function hide_coupon_field_on_woocommerce_checkout( $enabled ) {
	if ( is_checkout() ) {
		$enabled = false;
	}
	return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_woocommerce_checkout' );

Have any doubt, then comment here!

Remove woocommerce coupon field from woocommerce cart page

Here is a quick snippet to remove woocommerce coupon field from woocommerce cart page. When you enable the use of coupons, woocommerce adds the apply coupon form in cart and checkout page. For our customization want to remove woocommerce coupon field from cart page then place the following snippet in functions.php within your theme folder!.

function hide_coupon_field_on_woocommerce_cart( $enabled ) {
	if ( is_cart() ) {
		$enabled = false;
	}
	return $enabled;
}
add_filter( 'woocommerce_coupons_enabled', 'hide_coupon_field_on_woocommerce_cart' );

Have any doubt, then comment here!

Add new currency and symbol to woocommerce using filter

Here is a quick snippet to add new custom currency and symbol to wocommerce. Place the following snippet in functions.php within your theme folder. After adding this code your currency will be available in your WooCommerce settings page.

add_filter( 'woocommerce_currencies', 'add_my_custom_currency' );

function add_my_custom_currency( $currencies ) {
     $currencies['BOO'] = __( 'Your currency name', 'woocommerce' );
     return $currencies;
}

add_filter('woocommerce_currency_symbol', 'add_my_custom_currency_symbol', 10, 2);

function add_my_custom_currency_symbol( $currency_symbol, $currency ) {
     switch( $currency ) {
          case 'BOO': $currency_symbol = '$'; break;
     }
     return $currency_symbol;
}

Have any doubt, then comment here!

Redirect to home page after logout in WordPress

Add the following code in functions.php within your theme folder for redirect customers into home page after logout in WordPress

add_filter('logout_url', 'new_logout_url', 10, 2);
function new_logout_url($logouturl, $redir)
{
	$redir = get_option('siteurl');
	return $logouturl . '&redirect_to=' . urlencode($redir);
}

Have any doubt, then comment here!

Add Custom css in wordpress

You can use the following code for add custom CSS in WordPress. add your styles in commented part.

add_action(‘admin_head’, ‘my_study_style’);
function my_study_style()
{
//add your styles here
}

Have any doubt, then comment here!

Show All Categories as Links in WordPress

You can use the function get_the_category_list() for this process.

<?php
$categories = get_the_category();
$separator = ' ';
$output = '';
if($categories){
	foreach($categories as $category) {
		$output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
	}
echo trim($output, $separator);
}
?>

For more : http://codex.wordpress.org/Template_Tags/get_the_category