Get All WooCommerce Orders for a Customer

There are several ways to get all WooCommerce Orders for a Customer.
Here you can get all Woocommerce orders for a customer by customer email id.
Use the following code to fecth WooCommerce orders for a customer.
The following code will fecth all orders for a current user.

$customer_orders = get_posts( array(    
    'meta_key'    => '_customer_user',
    'meta_value'  => get_current_user_id(),
    'post_type'   => 'shop_order',
    'post_status' => array_keys( wc_get_order_statuses() ),
    'numberposts' => -1
) );

Have any doubt, then comment here!

How to change default product visibility in woocommerce

If you want to change default product visibility in woocommerce then add that following code in your functions.php file.
Here instead of “hidden” change your default visibility values.

function filter_woocommerce_product_visibility_default( $visible ) { 
    return "hidden"; 
	//return your default value here
}; 
add_filter( 'woocommerce_product_visibility_default', 'filter_woocommerce_product_visibility_default', 10, 1 );

Have any doubt, then comment here!

How to remove woocommerce product tabs programmatically

If you want to remove woocommerce product tabs programmatically in WordPress then add that following code in your functions.php file.
Here “woocommerce_product_tabs” filter is used for alter woocommerce product tabs.

add_filter( 'woocommerce_product_tabs', 'woocommerce_remove_product_tabs', 98 );
function woocommerce_remove_product_tabs( $tabs ) {

    unset( $tabs['description'] );      	// Remove the description tab
    unset( $tabs['reviews'] ); 			// Remove the reviews tab
    unset( $tabs['additional_information'] );  	// Remove the additional information tab
    return $tabs;
}

Have any doubt, then comment here!

How to remove woocommerce related products programmatically

If you want to remove woocommerce related products programmatically in WordPress then add that following code in your functions.php file.
Clear the query arguments for related products so none show.

function woocommerce_remove_related_products( $args ) {
	return array();
}
add_filter('woocommerce_related_products_args','woocommerce_remove_related_products', 10); 

Have any doubt, then comment here!

How to hide sale flash content in woocommerce

If you want to hide sale flash content in woocommerce then add that following code in your functions.php file.

add_filter('woocommerce_sale_flash', 'woocommerce_custom_hide_sales_flash');
function woocommerce_custom_hide_sales_flash()
{
    return false;
}

Have any doubt, then comment here!

Load default jQuery core file from CDN to WordPress

To load default jquery core file from CDN to WordPress, you need to simply copy and paste the following code in your theme’s functions.php file.

function replace_jquery() {
	if (!is_admin()) {
		wp_deregister_script('jquery');
		wp_register_script('jquery', 'https://code.jquery.com/jquery-1.12.4.min.js', false, '1.12.4');
		wp_enqueue_script('jquery');
	}
}
add_action('init', 'replace_jquery');

Have any doubt, then comment here!

How to add new menu/tab to WordPress toolbar

To add a new menu/tab to the WordPress toolbar, you need to simply copy and paste the following code in your theme’s functions.php file.

add_action( 'admin_bar_menu', 'add_toolbar_link_top', 999 );
function add_toolbar_link_top( $wp_admin_bar ) 
{	
	$args = array(
		'id'    => 'your-id',
		'title' => 'Your Title',
		'href'  => site_url(),
		'meta'  => array( 'class' => 'your-class-name' )
	);
	$wp_admin_bar->add_node( $args );
}

This code will add new menu in WordPress toolbar.

Have any doubt, then comment here!

How to save and get user profile modified date in WordPress

WordPress doesn’t have an default option to save modified date. So we have save modified date when user updating their profile.
You can save the modified date by adding the following code in your theme’s functions.php file.

/*Save profile modified date*/
function update_profile_modified_date( $user_id ) {
  update_user_meta( $user_id, 'modified_date', date("Y-m-d") );
}
add_action( 'profile_update', 'update_profile_modified_date' );

You can get this date by using get_user_meta() function. for example see below code.

$user_id=25; // replace your user id here
$modified_date = get_user_meta( $user_id, 'modified_date', true ); 

Have any doubt, then comment here!

Redirect back to current page after logout in WordPress

We have a filter in WordPress for set url to redirect after logout. You can use this filter to redirect back to current page after logout. Add the following code in your theme’s functions.php file..

/* Logout and return to the page they were on*/
function admin_logout_redirect($logouturl, $redir)
    {
        return $logouturl . '&redirect_to=http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    }
add_filter('logout_url', 'admin_logout_redirect', 10, 2);

Have any doubt, then comment here!

What are benefits of htaccess?

We can do following benefits stuff with htaccess.

  1. Routing the URL
  2. Mange Error Pages for Better SEO
  3. Redirection pages
  4. Detect OS (like Mobile/Laptop/Ios/Android etc)
  5. Set PHP Config variable
  6. Set Environment variable
  7. Allow/Deny visitors by IP Address
  8. Password protection for File/Directory
  9. Optimize Performance of website
  10. Improve Site Security