Limit Search Results to WooCommerce Products

Make sure your customers see only WooCommerce products when searching for items on your online store, giving them a better showcase of your offerings

Running a WooCommerce website requires some pretty straightforward tasks at hand each and every day. However, there are also some custom tweaks that some eCommerce admins would like to have for their websites. One of them is displaying just the products on their WooCommerce search page. This is done fairly easily and the code below has been tested with WordPress 5.6 and WooCommerce 4.8.0. However, as always, we advise you to thoroughly test the implementation of these custom code tweaks. In addition, either back up the entire site and database or use a service like Kinsta or WP Engine, which provide daily backups. Here’s the code below:

/** Limit WooCommerce Search Results To Products **/

function search_filter_pproducts($query) {
if ($query->is_search) {
$query->set(‘post_type’, ‘product’);
$query->set( ‘wc_query’, ‘product_query’ );
}
return $query;
}

If you have any questions or require custom WooCommerce coding, please contact us right away. We’ll be happy to provide you with assistance & services regarding items like these. In the meantime, have a happy holiday!

How to add additional gallery thumbnail sizes in WordPress

Create uniquely resized image thumbnails for use in content pages, blog posts, landing pages and galleries, speeding up the loading speed of your WordPress website

For many of us, the standard set of gallery sizes in WordPress aren’t enough and for many, they create their own set of issues. In turn, for any knowledgable WordPress developer, controlling what sizes are being created every time you upload an image is crucial for a proper, fast, and well-performing website. Below you will find a snippet that we’ve created for one of our clients, which you need to add to functions.php in order for it to work. Naturally, if you aren’t adding this prior to developing your website and uploading new media, you will have to regenerate all the thumbnails – easily done by the Regenerate Thumbnails plugin, which you can download & install on your WordPress site for free.

/** Gallery Sizes */

add_image_size(‘images-medium’, 450, 450, array(‘center’, ‘center’));
add_image_size(‘gallery-small’, 480, 300, array(‘center’, ‘center’));
add_image_size(‘gallery-medium’, 720, 405, array(‘center’, ‘center’));
add_image_size(‘gallery-thumb’, 500, 350, true );
add_image_size(‘woocommerce_single_resized’, 1000, 1000, true );

/** Media Gallery Sizes Add-on */

add_filter( ‘image_size_names_choose’, ‘my_custom_sizes’ );

function my_custom_sizes( $sizes ) {
return array_merge( $sizes, array(
‘gallery-small’ => __( ‘Gallery Medium Cropped’ ),
‘gallery-medium’ => __( ‘Gallery Medium’ ),
) );
}

In this case, we’re adding 5 additional thumbnail sizes that we need for theme placements for our client’s website. These items are catered to a 1440px wide design grid size we’re using, allowing us to fill out the pages perfectly, all without adding too much weight to them. Naturally, it would be a great idea to use the <picture> element within the template’s design or ACF (Advanced Custom Forms). This will give you more leeway in terms of loading image sizes that fit each screen, allowing you to load smaller and less heavy imagery. In turn, this will undoubtedly speed up your site, as it stops loading large thumbnail sizes, albeit filling out the content area real estate perfectly. Below you will find an example of what is done on EV Car Scene, one of the websites we manage & develop.

EV Car Scene - Custom Sized Thumbnails For Use In Content Pages
EV Car Scene – Custom Sized Thumbnails For Use In Content Pages
DISCLAIMER: Please use the code, advice, and information presented on this website with caution. Nucleus J.D.O.O, or any of its employees, cannot be held responsible for any damages that this code might cause. We always try to update the code shown on our website, but we cannot guarantee its functionality with various themes, templates, or coding. Please ensure that you test each code thoroughly in order to use it safely.

 

How To Send A CC or BCC of Customer E-Mails in WooCommerce To Other E-Mail Address

For those running WooCommerce either for themselves or for their clients, the question we’re about to answer below comes into view quite often. Basically, most of our  clients want to have this option. After all, checking the e-mails that are sent to your customers is a great way to further troubleshoot any issues, but also, to ensure that  all the e-mails get sent out and that they contain all the necessary information. That’s why the code snippet added below will help you CC or BCC your customer e-mails to another e-mail address, preferably your own. Here’s the code below.

/** Send out a copy of WooCommerce e-mails to another address **/

add_filter( ‘woocommerce_email_headers’, ‘woocommerce_email_headers_nucleusmarketing’, 10, 4 );
function woocommerce_email_headers_nucleusmarketing( $header, $email_id, $email_for_obj, $email_class ) {
// Bcc this email address to *all* WooCommerce emails.
$header .= ‘Bcc: accounting@nucleusmarketing.hr’ . “\r\n”;

// Add another address to the Order Completed emails only.
if ( ‘customer_completed_order’ == $email_id ) {
$header .= ‘Bcc: accounting@nucleusmarketing.hr’ . “\r\n”;
}

return $header;
}

While WooCommerce doesn’t provide this feature out of the box, the above solution will simply create a BCC to your accounting and/or any e-mail address you want the customer confirmation e-mails (eg. processing order, completed order, etc.) to go to. It’s easy, works with the current WordPress 5.6 and WooCommerce 4.8.0 versions. Please free to send us a note if you find this code not working, we’ll appreciate it.