Remove woocommerce related products programmatically in WordPress

For our customization want to remove woocommerce related products programmatically then place the following snippet in functions.php within your theme folder!.
The remove_action can be used for removing the related products from woocommerce page.

remove_action( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products',20);
remove_action( 'woocommerce_after_single_product', 'woocommerce_output_related_products',10); 

Have any doubt, then comment here!

Check post type and remove media buttons in wp-admin

For our customization want to check post type and remove media buttons in wp-admin then place the following snippet in functions.php within your theme folder!. add your custom post type slug instead of custom-post-type.

add_action('admin_head', 'check_post_type_and_remove_media_buttons');
function check_post_type_and_remove_media_buttons()
{
	global $post;
	if($post->post_type == 'custom-post-type')
	{
		remove_action( 'media_buttons', 'media_buttons' );
	}
}

Have any doubt, then comment here!

Remove custom post type slug from URL

For our customization want to remove custom post type slug from url then place the following snippet in functions.php within your theme folder!. add your custom post type slug instead of custom-post-slug.

function remove_custom_post_type_slug( $post_link, $post, $leavename ) {

    $post_link = str_replace( '/custom-post-slug/', '/', $post_link );

    return $post_link;
}
add_filter( 'post_type_link', 'remove_custom_post_type_slug', 10, 3 );

Have any doubt, then comment here!

Add specific country to woocommerce country list

For our customization want to add specific country to woocommerce country list then place the following snippet in functions.php within your theme folder!.

function woo_add_specific_country( $country ) 
{
   unset($country["US"]);
   return $country; 
}
add_filter( 'woocommerce_countries', 'woo_add_specific_country', 10, 1 );

Have any doubt, then comment here!

Remove specific country from woocommerce country list

For our customization want to remove specific country from woocommerce country list then place the following snippet in functions.php within your theme folder!.

function woo_remove_specific_country( $country ) 
{
   unset($country["US"]);
   return $country; 
}
add_filter( 'woocommerce_countries', 'woo_remove_specific_country', 10, 1 );

Have any doubt, then comment here!

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

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

function set_wp_mail_from_address( $original_email_address )
{
	$cw_email_from_address = get_option( 'admin_email' );
	return $cw_email_from_address;
}
add_filter( 'wp_mail_from', 'set_wp_mail_from_address' );

Have any doubt, then comment here!

Create New page if its not exists in WordPress programmatically

For our customization want to create new page if it’s not exists then place the following snippet in functions.php within your theme folder!.

function create_new_page()
{
    global $user_ID;
    if( get_page_by_title('New Page')==NULL )
    {
	$new_post = array(
		      'post_title' => 'New Page',
		      'post_content' => 'New post content',
		      'post_status' => 'publish',
		      'post_date' => date('Y-m-d H:i:s'),
		      'post_author' => $user_ID,
		      'post_type' => 'page'
		);
	$post_id = wp_insert_post($new_post);
   }
}
add_action('init','create_new_page');

Have any doubt, then comment here!

Increase the_excerpt() content length in wordpress

For our customization want to increase the_excerpt() content length then using the excerpt_length filter. by default expert length is 55. for example you want to change length in to 100 then place the following snippet in functions.php within your theme folder!.

function increase_custom_excerpt_length( $length ) {
    return 100;
}
add_filter( 'excerpt_length', 'increase_custom_excerpt_length', 999 );

Have any doubt, then comment here!