Set wp mail from name when sending mail using wp_mail()

For our customization want to set wp mail from name when sending mail using wp_mail() then place the following snippet in functions.php within your theme folder!.

function set_wp_mail_from_name( $original_email_from )
{
	$cw_email_from_name = 'Testing';
	return $cw_email_from_name;
}
add_filter( 'wp_mail_from_name', 'set_wp_mail_from_name' );

Have any doubt, then comment here!

Check user meta data when user login in WordPress

For our customization want to check user meta when user login in wordpress then place the following snippet in functions.php within your theme folder!.

function check_user_meta_data($user) 
{
	$st=get_user_meta( $user->ID, 'user_status', true);
	 if ($st != 'active') {
        $user = new WP_Error( 'denied', __("ERROR: Account Not Active..") );
    }
    return $user;
		
}
add_action('wp_authenticate_user', 'check_user_meta_data', 10, 2);

Have any doubt, then comment here!

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!