Category: Theme

WooCommerce edit Myaccount page navigation

Add this code in your theme function.php

function wc_limit_account_menu_items(){
 $items = array(
 // 'dashboard' => __( 'Dashboard', 'woocommerce' ),
 'orders' => __( 'Orders', 'woocommerce' ),
 // 'downloads' => __( 'Downloads', 'woocommerce' ),
 'edit-address' => __( 'Address', 'woocommerce' ),
 // 'payment-methods' => __( 'Payment Methods', 'woocommerce' ),
 'edit-account' => __( 'Edit Account', 'woocommerce' ),
 // 'customer-logout' => __( 'Logout', 'woocommerce' )

 return $items;
add_filter( 'woocommerce_account_menu_items', 'wc_limit_account_menu_items' );

WordPress add error message on password protected page

WordPress stored the latest entered password  as a secure hash in a cookie named 'wp-postpass_' . COOKIEHASH.

When the password form is called, that cookie has been validated already by WordPress. So you just have to check if that cookie exists: If it does and the password form is displayed, the password was wrong.

add_filter( 'the_password_form', 'wpse_71284_custom_post_password_msg' );

 * Add a message to the password form.
 * @wp-hook the_password_form
 * @param string $form
 * @return string
function wpse_71284_custom_post_password_msg( $form )
 // No cookie, the user has not sent anything until now.
 if ( ! isset ( $_COOKIE[ 'wp-postpass_' . COOKIEHASH ] ) )
 return $form;

 // Translate and escape.
 $msg = esc_html__( 'Sorry, your password is wrong.', 'your_text_domain' );

 // We have a cookie, but it doesn’t match the password.
 $msg = "<p class='custom-password-message'>$msg</p>";

 return $msg . $form;

Set, get and destroy cookies in WordPress

You can either retrieve and manipulate cookies on the server side using PHP or client side, using JavaScript.

In PHP, you set cookies using setcookie(). Note that this must be done before any output is sent to the browser which can be quite the challenge in WordPress. You’re pretty much limited to some of the early running hooks which you can set via a plugin or theme file

add_action('init', function() {
    // yes, this is a PHP 5.3 closure, deal with it
    if (!isset($_COOKIE['my_cookie'])) {
        setcookie('my_cookie', 'some default value', strtotime('+1 day'));

Retrieving cookies in PHP is much easier. Simply get them by name from the $_COOKIE super global’

$cookieValue = $_COOKIE['my_cookie'];

Unsetting a cookie requires setting one with an expiration date in the past, something like

setcookie('my_cookie', null, strtotime('-1 day'));

WooCommerce: Add custom Add To Cart Message & Custom “Continue Shopping Link”

Add this code in function.php




* Custom Add To Cart Messages

* Add this to your theme functions.php file


add_filter( 'wc_add_to_cart_message', 'woocommrece_custom_add_to_cart_message' );

function woocommrece_custom_add_to_cart_message() {

global $woocommerce;


// Output success messages

if (get_option('woocommerce_cart_redirect_after_add')=='yes') :


$return_to = get_permalink(woocommerce_get_page_id('shop'));// Give the url, you want to redirect


$message = sprintf('<a href="%s">%s</a> %s', $return_to, __('Continue Shopping &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );


else :


$message = sprintf('<a href="%s">%s</a> %s', get_permalink(woocommerce_get_page_id('cart')), __('View Cart &rarr;', 'woocommerce'), __('Product successfully added to your cart.', 'woocommerce') );




return $message;


/* Custom Add To Cart Messages */


Woo-commerce: add to cart button redirect to checkout

Add this code in your function.php

** Add to cart redirect to checkout
add_filter ('add_to_cart_redirect', 'redirect_to_checkout');

function redirect_to_checkout() {
    global $woocommerce;
    $checkout_url = $woocommerce->cart->get_checkout_url();
    return $checkout_url;



WordPress: Read more not working

When you are creating a new wordpress theme, some time read more tag not working you blog. “Read more” are not showing on the front end of your blog though you are using read more tag in wordpress post.


To solve this problem you need to follow two simple step:


Add  the <?php global $more;?> before the loop.


Add this code inside loop.

<?php $more = 0;the_content(__('Read more', 'theemename')); ?>