Below is the list of some super useful WooCommerce code snippets, which help you while customizing the WooCommerce store. This is the list of some extremely useful snippets. These are the simple action and filters of WooCommerce to change the default functionalities of WooCommerce store.
See the below lists of useful code snippets carefully and use it to your WooCommerce based websites.
If you want to create a direct link for Add to the cart of any product from the website, then you can create by using the below URL structure:
http://yourwebsite.com/checkout/?add-to-cart=product_id
By default, WooCommerce displayed the 12 products per page, but if you want to change the number of products displayed on the product archive page, then use this below code to your functions.php file in your theme.
1 2 3 4 5 6 7 8 | add_filter( 'loop_shop_per_page', 'new_loop_shop_per_page', 20 ); function new_loop_shop_per_page( $cols ) { // $cols contains the current number of products per page based on the value stored on Options -> Reading // Return the number of products you wanna show per page. $cols = 9; return $cols; } |
If you do not need the breadcrumbs on your website anymore and want to remove it, then use the below code to your functions.php file in your currently activated theme.
1 2 3 4 5 6 | add_action( 'init', 'fwm_remove_breadcrumbs' ); function fwm_remove_breadcrumbs() { //action to remove WooCommerce breadcrumbs remove_action( 'woocommerce_before_main_content', 'woocommerce_breadcrumb', 20, 0 ); } |
Don’t like to display the “out of stock” words for your non-inventory products and want to change it by other words like “Sold out”, “Not Available”, or something else, then use the below code at the end of your functions.php file of your current activated theme.
1 2 3 4 5 6 | add_filter('woocommerce_get_availability', 'availability_filter_func'); function availability_filter_func($availability) { $availability['availability'] = str_ireplace('Out of stock', 'Not Available', $availability['availability']); return $availability; } |
You can also change the number of products displayed per row on your archive page by using the below code to your functions.php file of your current activated theme. Below code will override the default number of products per row.
1 2 3 4 5 | // Override theme default specification for product # per row function loop_columns() { return 5; // 5 products per row } add_filter('loop_shop_columns', 'loop_columns', 999); |
Hope these code snippets helped you, If you have any question regarding it, then feel free to add your comments in below comment section. Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: Top Useful WooCommerce Code Snippets, woocommerce tutorial, woocommerce tutorials, woocommerce useful code, wordpress woocommerce tutorial