Category: Wordpress

Remove text editor for custom post type in WordPress

For our customization want to remove text editor for custom post type then place the following snippet in functions.php within your theme folder!.

function remove_text_editor_custom_post_type() {
    remove_post_type_support( 'post_type_name', 'editor' );
}
add_action('init', 'remove_text_editor_custom_post_type');

Have any doubt, then comment here!

Get woocommerce cart count in WordPress

For our customization want to get the count of number of products in a cart then use the following code.

global $woocommerce;
$count = $woocommerce->cart->cart_contents_count;
if ($count > 0) 
{
	echo $count;
}
else
{
 echo "No products in cart";
}

Have any doubt, then comment here!

Create widget in WordPress programmatically

For our customization want to create a new widget in WordPress programmatically then place the following snippet in functions.php within your theme folder!.

add_action( 'widgets_init', 'create_new_widget' );
function create_new_widget() 
{
    register_sidebar( array(
        'name' => __( 'Custom Sidebar', 'theme-slug' ),
        'id' => 'custom_sidebar',
        'description' => __( 'Your widget description here', 'theme-slug' ),       
    ) );
}

After that you can call this sidebar by following code. Wherever you want add the following code in that particular place.

dynamic_sidebar( 'left-sidebar' );

Have any doubt, then comment here!

Change order note label in woocommerce checkout page

For our customization want to change woocmmerce order notes label in checkout page then place the following snippet in functions.php within your theme folder!.

add_filter( 'woocommerce_checkout_fields' , 'change_order_note_label_in_woocommerce_checkout_page' );
function change_order_note_label_in_woocommerce_checkout_page( $fields ) {
     $fields['order']['order_comments']['label']="Special Insructions";
     return $fields;
}

Have any doubt, then comment here!

Change woocmmerce out of stock text in wordpress

For our customization want to change woocommerce Out of stock text to Sold Out then place the following snippet in functions.php within your theme folder!.

add_filter('woocommerce_get_availability', 'change_woocommerce_out_of_stock_text');
function change_woocommerce_out_of_stock_text($availability)
{
	$availability['availability'] = str_ireplace('Out of stock', 'Sold Out', $availability['availability']);
	return $availability;
}

Have any doubt, then comment here!

Remove woocommerce order notes from checkout page

For our customization want to remove woocommerce order notes section from checkout page then place the following snippet in functions.php within your theme folder!.

add_filter( 'woocommerce_checkout_fields' , 'remove_woocommerce_order_notes_from_checkout_page' );
function remove_woocommerce_order_notes_from_checkout_page( $fields ) {
     unset($fields['order']['order_comments']);
     return $fields;
}

Have any doubt, then comment here!

Get particular user meta data by user email address in WordPress

Here is a quick snippet to get particular user meta data by $email_address in WordPress. The following code will print particular user meta data for particular user.

$user = get_user_by( 'email', $email_address );
$user_id=$user->ID;
$key = 'you_key_name';
$single = true;
$meta_value = get_user_meta( $user_id, $key, $single );
echo $meta_value;

Have any doubt, then comment here!

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!