Listing custom taxonomy terms by first letter

Add this on function.php

add_filter( 'terms_clauses', 'terms_clauses_47840519', 10, 3 );
function terms_clauses_47840519( $clauses, $taxonomies, $args ){
    global $wpdb;

    if( !isset( $args['__first_letter'] ) ){
        return $clauses;
    }

    $clauses['where'] .= ' AND ' . $wpdb->prepare( "t.name LIKE %s", $wpdb->esc_like( $args['__first_letter'] ) . '%' );

    return $clauses;

}

and call it with something like

$terms = get_terms( array(
    'taxonomy' => $taxonomy,
    '__first_letter' => 'a', // desired first letter
) );

Search custom taxonomy term by name

// We get a list taxonomies on the search box
function get_tax_by_search($search_text){

$args = array(
    'taxonomy'      => array( 'my_tax' ), // taxonomy name
    'orderby'       => 'id', 
    'order'         => 'ASC',
    'hide_empty'    => true,
    'fields'        => 'all',
    'name__like'    => $search_text
); 

$terms = get_terms( $args );

 $count = count($terms);
 if($count > 0){
     echo "<ul>";
     foreach ($terms as $term) {
       echo "<li><a href='".get_term_link( $term )."'>".$term->name."</a></li>";

     }
     echo "</ul>";
 }

}

// sample
get_tax_by_search('Foo');

wp_signon function, issues

After calling wp_signon() or wp_set_auth_cookie(), you should redirect the user to make sure the new cookie is being loaded.

This can be done by using the following code right after your wp_signon() or wp_set_auth_cookie() call:

wp_redirect($_SERVER[‘REQUEST_URI’]);
exit;
In case you want to redirect the user to a specific page, you can replace $_SERVER[‘REQUEST_URI’] with the URL where you want to redirect the user to.

A sidenote: you should make sure that this code is called before the headers are being sent, as wp_redirect() will not work after the headers are sent.

HTML/Template:

<form id="login1" name="form" action="" method="post">
 <input id="username" type="text" placeholder="Username" name="username"><br>
 <input id="password" type="password" placeholder="Password" name="password"> 
 <input id="submit" type="submit" name="submit" value="Submit">
 </form> 

Function file of theme or plugin

 function custom_login() {
  global $wpdb;  
    //We shall SQL escape all inputs  
    if($_POST){
    $username = $wpdb->escape($_REQUEST['username']);  
    $password = $wpdb->escape($_REQUEST['password']);  
    $remember = $wpdb->escape($_REQUEST['rememberme']);  
   
    if($remember) $remember = "true";  
    else $remember = "false";  
   
    $login_data = array();  
    $login_data['user_login'] = $username;  
    $login_data['user_password'] = $password;  
    $login_data['remember'] = $remember;  
   
    $user_verify = wp_signon( $login_data, false );   
    if ( is_wp_error($user_verify) )   
    {  
        $errors = "Invalid login details";  
       // Note, I have created a page called "Error" that is a child of the login page to handle errors. This can be anything, but it seemed a good way to me to handle errors.  
     } else
    {    
        //wp_set_current_user($user_verify->ID);
        wp_redirect($_SERVER['REQUEST_URI']);
      // echo "window.location.href='". home_url() ."'";  
       exit();  
     } } }
     // run it before the headers and cookies are sent
add_action( 'after_setup_theme', 'custom_login' );

Displaying posts with only upcoming dates according their custom field date value

<?php
$today = date('m/d/Y', strtotime('+2 hours')); //Use the date format you used for the start date
$the_query = new WP_Query( array(
  'post_type' => 'events',
  'posts_per_page' => 5,
  'meta_key' => 'start_date',
  'orderby' => 'meta_value',
  'order' => 'ASC',
  'meta_query' => array(
  array(
    'key' => 'start_date',
    'value' => $today,
    'compare' => '>=',
    'type' => 'DATE'
  ))
));
?>

WordPress: Add plugin settings link to Plugins page

When creating a plugin that has its own settings page, it’s frequently helpful to make a connection to the settings page straight from the Plugins list – this spares clients the time it takes to discover where precisely your module shows up in the administrator menu. Here is a basic code scrap that makes the settings interface for you.

<?php
function plugin_add_settings_link( $links ) {
    $settings_link = '<a href="options-general.php?page=plugin_name">' . __( 'Settings' ) . '</a>';
    array_push( $links, $settings_link );
  	return $links;
}
$plugin = plugin_basename( __FILE__ );
add_filter( "plugin_action_links_$plugin", 'plugin_add_settings_link' );
?>

Just replace the href attribute with the link to the plugin settings page and rename the function to something slightly more unique.

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;
}

WooCommerce checkout template by hooks

/**
 * Add a content block after all notices, such as the login and coupon notices.
 *
 * Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-checkout.php
 */
add_action( 'woocommerce_before_checkout_form', 'skyverge_add_checkout_content', 12 );
function skyverge_add_checkout_content() {
 echo 'This content that you can use to tell customers stuff. You could make it a div class="checkout-message" and style it if you wanted.';
}

/**
 * Add a content in a notice instead. Let's add it before other notices with a priority = 9
 *
 * Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-checkout.php
 */
add_action( 'woocommerce_before_checkout_form', 'skyverge_add_checkout_success', 9 );
function skyverge_add_checkout_success() {
 wc_print_notice( __( 'A success message with high priority.', 'woocommerce' ), 'success' );
}


/**
 * Add an info notice instead. Let's add it after other notices with priority = 11
 *
 * Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/form-checkout.php
 */
add_action( 'woocommerce_before_checkout_form', 'skyverge_add_checkout_notice', 11 );
function skyverge_add_checkout_notice() {
 wc_print_notice( __( 'A notice message instead.', 'woocommerce' ), 'notice' );
}


/**
 * Add add a notice before the payment form - let's use an eror notice. Could also use content, etc.
 *
 * Reference: https://github.com/woothemes/woocommerce/blob/master/templates/checkout/review-order.php
 */
add_action( 'woocommerce_review_order_before_payment', 'skyverge_before_paying_notice' );
function skyverge_before_paying_notice() {
 wc_print_notice( __( 'An error message.', 'woocommerce' ), 'error' );
}

WooCommerce hide unavailable veriations from dorpdown

If there are greater than 20 variations in the product, it will use ajax to find matches and won’t hide combinations (because doing so would mean loading all variations before display).

Use is code in your functions.php

function custom_wc_ajax_variation_threshold( $qty, $product ) {
	return 10;
}

add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 );

 

Change the return value as per your number of combination.

Hide other shipping methods when FREE SHIPPING is available

/**
 * woocommerce_package_rates is a 2.1+ hook
 */
add_filter( 'woocommerce_package_rates', 'hide_shipping_when_free_is_available', 10, 2 );
 
/**
 * Hide shipping rates when free shipping is available
 *
 * @param array $rates Array of rates found for the package
 * @param array $package The package array/object being shipped
 * @return array of modified rates
 */
function hide_shipping_when_free_is_available( $rates, $package ) {
 	
 	// Only modify rates if free_shipping is present
  	if ( isset( $rates['free_shipping'] ) ) {
  	
  		// To unset a single rate/method, do the following. This example unsets flat_rate shipping
  		unset( $rates['flat_rate'] );
  		
  		// To unset all methods except for free_shipping, do the following
  		$free_shipping          = $rates['free_shipping'];
  		$rates                  = array();
  		$rates['free_shipping'] = $free_shipping;
	}
	
	return $rates;
}

Show only free shipping in all states except…

Show only free shipping in all states except exclusion list, hide free shipping if the customer is in one of the states listed:

/**
 * Hide ALL shipping options when free shipping is available and customer is NOT in certain states
 * Hide Free Shipping if customer IS in those states
 *
 * UPDATED FOR WOOCOMMERCE 2.1
 *
 * Change $excluded_states = array( 'AK','HI','GU','PR' ); to include all the states that DO NOT have free shipping
 */
add_filter( 'woocommerce_package_rates', 'hide_all_shipping_when_free_is_available' , 10, 2 );

/**
 * Hide ALL Shipping option when free shipping is available
 *
 * @param array $available_methods
 */
function hide_all_shipping_when_free_is_available( $rates, $package ) {
 
	$excluded_states = array( 'AK','HI','GU','PR' );
	if( isset( $rates['free_shipping'] ) AND !in_array( WC()->customer->shipping_state, $excluded_states ) ) :
		// Get Free Shipping array into a new array
		$freeshipping = array();
		$freeshipping = $rates['free_shipping'];
 
		// Empty the $available_methods array
		unset( $rates );
 
		// Add Free Shipping back into $avaialble_methods
		$rates = array();
		$rates[] = $freeshipping;
 
	endif;
 
	if( isset( $rates['free_shipping'] ) AND in_array( WC()->customer->shipping_state, $excluded_states ) ) {
 
		// remove free shipping option
		unset( $rates['free_shipping'] );
 
	}

	return $rates;
}

Enable Shipping Methods on a per Class / Product Basis

If you want to have more flexibility, we recommend you to use this free plugin!

Source: http://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/