If you have no idea about WordPress code or how to edit WordPress php the best way to get started is to install a php snippets plugin so you don’t make any mistakes you might have to fix up.

Instead of editing the WordPress functions php file directly you can install this plugin from which you can copy and paste the following snippers so they will take effect.

This plugin is similar to a WordPress source code editor.


PHP snippets plugin WordPress

Download the PHP snippets plugin WordPress


I have found some snippets that have helped me optimize my Woocommerce WordPress website over the years so i thought i would share them with some of my readers.

I know we have all been in the following situation before.

You have something you would like to change on Woocommerce but there is no plugin for it, so you search google for hours scouring places like stack-overflow for a snippet of PHP that will fix the job, hoping that someone has searched for and asked the same question you are trying to find a solution for.

I have personally done this for hours until I have found a solution.

I have researched and found 9 WordPress PHP snippets that have helped optimize my Woocommerce sites, many of which hide features I have found are not needed or add too much clutter to the product pages and checkout pages on Woocommerce.


When I work with eCommerce sites I am all about less clutter and more focus on the objective!

The main priority as a seller is always adding a product to the cart and checking out so you make the sale and the money goes into your product.

There are many people who’s primary objective is to split A/B test product pages to optimize them for sales.

This involves various factors such as website speed, UX design, usability and decluttering features that are not needed.

I think that in many situations when people have an eCommerce website they have worked hard to build, it comes to a stage where they are getting traffic but no one is buying.

If you have seen the reaction on Reddit from people at this stage in their business venture they will usually react by creating a new post in Reddits such as r/Entrepreneur and r/juststart an alarmist title and a direct approach to creating controversy and blasting everyone who disagrees with them. See the example below.


seobetter ebook

SEOBetter: Step-by-step How to grow your traffic to 70,000 unique visitors in 11 weeks.

Get this eBook PDF for free (RRP $9.95 on Amazon Kindle), plus new updates and thoroughly tested online marketing techniques by subscribing to my newsletter.

sign up with facebook

You can also sign up to our newsletter with Facebook (quicker and easier)

Reddit Rant from angry drop shipper who didn’t make much money

This guy was not happy!

But hey, this happens to everyone, either you quit or try a new approach and keep grinding.

When you are building an eCommerce website or a Drop shipping website it is best to realize a few things.

You are going to fail when you try new things, this could be trying new software, plugins, advertising or building links for SEO.

You need to learn from this failures or find someone previously who is working on the same thing, who has failed and now knows what works and what doesn’t.

In saying this, someone who has years of experience on eCommerce cant have tried every new app or software to come out on the market, though with SEO link building and optimizing eCommerce.

Back to the point.

You will find from this post that some of these snippets may be useful to some and not to others, though IF they get indexed through my keyword research based on the search term, you may find this page and it will save you an hour or two of trying to Google the solution.

How to Remove Quantity Field from Woocommerce Product Page

Quantity is made for the backend of a Woocommerce website so admin’s can update stock amounts based on what is in the warehouse. This is a feature that is not needed on the single product page of Woocommerce, showing this to the customer has absolutely no effect.

Some may argue that it has an FOMO (fear of missing out) effect, though it is highly unlikely.

So if you have been trying to Hide the Woocommerce Product Quantity Field from Product Page you can add this PHP snippet.

If you have products that sell in large quantities then you wont want to add this snippet which will make Woocommerce remove plus minus buttons.

    function quantity_wp_head() {
    if ( is_product() ) {
    <style type="text/css">.quantity, .buttons_added { width:0; height:0; display: none; visibility: hidden; }</style>
        add_action( 'wp_head', 'quantity_wp_head' );

Woocommerce: How to Remove “What is PayPal?” at Checkout

If you have not noticed by now with the default Woocommerce checkout it has the included Paypal plugin. When you click on the tab to use Paypal it has a link that has “What is Paypal?”.

If you or a customer does not know what Paypal is by now then you should probably not be setting up an eCommerce website.

This may not seem like a big deal, though when you checkout on mobile, you have a limited amount of space!

Lets admit it..

Some people have fat fingers dwindling away on small mobile screens.

This can be a problem when you go to click “Paypal” as the checkout option on Woocommerce, but your fingers are to fat and you click the “What is Paypal” link instead, which opens a new window, wastes your time and you leave the checkout with the impression that the site you just shopped on is stupid and slow.

HANDPICKED RELATED CONTENT:  The Best GDPR cookie consent WordPress plugins 2021

We don’t want our customers thinking this about our website!

So if you have been searching for “How to remove the PayPal logo and “what is PayPal link” the PHP snippet solution is below.

Show product star ratings and count below the price in Woocommerce archive pages

When a user is browsing your website he most likely could be persuaded to buy one product over another based on its rating.

On many Woocommerce themes it only will show the star rating and count on a single product page and not the category or archive page.

This is a snippet that will show the Woocommerce star rating code under the product on the category pages.

If you have been searching google for “How to display rating stars under product thumbnails.”

Look no further!

The php snippet to achieve this is below.

add_filter( 'woocommerce_gateway_icon', 'bbloomer_remove_what_is_paypal', 10, 2 );

function bbloomer_remove_what_is_paypal( $icon_html, $gateway_id ) {
// the apply_filters comes with 2 parameters: $icon_html, $this->id
// hence we declare 2 parameters within the function
// and the hook above takes the "2" as we decided to pass 2 variables

if( 'paypal' == $gateway_id ) {
// we use one of the passed variables to make sure we only
// run this function for the gateway ID == 'paypal'

$icon_html = '<img src="/wp-content/plugins/woocommerce/includes/gateways/paypal/assets/images/paypal.png" alt="PayPal Acceptance Mark">';
// in here we define our own $icon_html
// note there is no mention of the "What is PayPal"
// all we want is to repeat the part with the paypal logo

// endif

return $icon_html;
// we send the $icon_html variable back to the system
// if PayPal, the system will use our custom $icon_html
// if not, the system will use the original $icon_html


Starting at $30/mo

  • Perfect for people who want a WordPress that is Secure like Fort Knox
  • Specialization in Google Cloud Platform WordPress website hosting
  • Free migration, CDN and SSL certificates

Kinsta is a managed WordPress hosting provider that takes care of all the back end optimization for your website, so it runs at an optimized speed for visitors. They have cutting edge Google Cloud servers and take WordPress hosting seriously. They specialize in high-traffic WordPress websites, if you want a safe and secure host, they are the best partner to choose.

Hide Added to Cart message in Woocommerce

When you add a product to cart in Woocommerce you have the option from the settings to either direct the customer to the cart or have it added to a floating shopping cart icon which will show the total products so the customer can checkout later.

If your website has a floating shopping cart icon, the question remains.

Why do you have to tell the customer twice that they have added the item to the shopping cart!

This is super annoying for me and I have always wanted to remove add to cart notice on my sites.

If you want to Remove / Hide Woocommerce Added to Cart Message then you can use this PHP snippet.

add_filter( 'wc_add_to_cart_message_html', '__return_false' );

Hide weight / dimensions in single product’s additional information tab

With all products in Woocommerce it will have an additional information tab, this shows information about the product such as dimensions and varied product attributes.

In some cases you may want to hide the weight and height dimensions from your customer as it is only needed to calculate shipping costs.

Here is the plugin to PHP snippet to hide a Woocommerce product’s weight and dimensions

 * Hides the product's weight and dimension in the single product page.
add_filter( 'wc_product_enable_dimensions_display', '__return_false' );

function my_attribute_hider ( $attributes ) {
if ( isset( $attributes['pa_colour'] ) ){
    unset( $attributes['pa_colour'] );
return $attributes;
add_filter( 'woocommerce_get_product_attributes', 'my_attribute_hider' );

Disable Default Image Links in WordPress


What is it about WordPress permalinks – Stop Images Linking to Themselves please..

This is one you may not have noticed until a few months later when your images start ranking in Google higher then your blog post.

When you add an image it will have a default image link WordPress which will link to a URL which if unchecked will be indexed by Google.

There is probably a plugin that will Disable image attachment links though you may not want this site wide on your website as it can effect other areas of your site.

Here is the PHP snippet which will Automatically Remove Default Image Links in WordPress

function wpb_imagelink_setup() {
    $image_set = get_option( 'image_default_link_type' );
    if ($image_set !== 'none') {
        update_option('image_default_link_type', 'none');
add_action('admin_init', 'wpb_imagelink_setup', 10);

Using CDN images with WPML multisite installation

Go to WPML and get your site language translated!

This snippet is strictly for people who run WPML (a highly recommended tool to increase traffic) if installed correctly. We plan to cover how this works in the future, the secret is using href-lang without getting penalized with duplicate content.

Back to the point.

If you are running a CDN and WPML on a multi-site you may find that it does not use CDN images on all the websites only the main one then duplicates the images into each language.

This defeats the purpose which is to speed up your website by delivering content from a CDN.

When you WPML Images are not cached from CDN it might be a WPML Media Translation issue with the CDN but here is a snippet to save you time trying to solve the problem.

add_filter ('wp_get_attachment_image_src', 'change_product_image_src');   function change_product_image_src ($image) {    
$image[0] = apply_filters('wpml_permalink', $image[0], apply_filters('wpml_default_language', NULL));     
return $image; }

Resize Woocommerce product catalogue image size


Everyone has to have come across this issue with Woocommerce and I have no idea why they don’t fix it.

When you upload products to Woocommerce sometimes the thumbnails created are not all the same size.

When this happens your product category page will be populated with products with images that are all different sizes.

I once had an image that was around 700 px high! While all the rest were around 250 px.

HANDPICKED RELATED CONTENT:  WooCommerce Guide | Definitive Step by Step SEO Help & Tips - 19x your eCommerce revenue in 5 months (2021)

I know this may be bad SEO to do a keyword list, but I searched for HOURS!

Trying to find a solution to resize the images in Woocommerce archive pages. All the solutions said “change the thumbnail size settings in Woocommerce then recreate the thumbnails with a plugin”.

First of all, if you have more than 500 products this will take a S**T load of time and will put a strain on your websites server.

Secondly, every time you try and recreate your thumbnails it uses more space on your server to store the files, which is unnecessary.

Without a lie i looked for about 5 hours, i tried 3 separate plugins and nothing worked. Here are the keywords I used to try and find the solution when searching in Google.

Maybe you might find this post the same way.

  • Change the grid view of Woocommerce product catalogue
  • Change the layout of Woocommerce category page
  • Resize Woocommerce category image size
  • Resize Woocommerce product catalogue image size
  • Resize Woocommerce category images with css
  • Resize Woocommerce category product page images
  • Woocommerce product category page row height
  • Keep all Woocommerce category images the same size
  • Keep all Woocommerce catalogue images the same size
  • Woocommerce category image height
  • Woocommerce category layout plugin
  • Woocommerce category grid view plugin
  • Woocommerce category page template
  • Woocommerce category page template over ride
  • Woocommerce category image Thumbnail Cropping
  • Woocommerce category image thumbnail soft crop
  • Automatic Thumbnail Resizing Woocommerce
  • Woocommerce Category Images Thumbnails
  • Resize Woocommerce category images

So from all of this searching i found the solution in 4 lines of CSS code!

Can you believe it, I could not, i was astonished that after all that searching i had found the solution and it was as easy as that.


The explanation is as follows:

With this specific CSS3 object-fit/object-position method it works instantly by specifying how an object (image or video) should fit inside its box. object-fit options includes: “contain” (fit according to aspect ratio), “fill” (stretches object to fill) and “cover” (overflows box but maintains ratio).

The SEObetter team

This is where object-position allows the object to be repositioned like a background-image does.

Here is the CSS code you can add to Appearance > Customize > Additional CSS

.woocommerce ul.products li.product a img {
 width: 100%;
 height: 200px;
 object-fit: contain; }

Prevent robots crawling “add-to-cart” links on Woocommerce

This is a small snippet which can have a massive effect to help with reduced CPU usage on your server this may decrease your monthly cost if this is a factor in your billing quota which is usually the case with cloud hosting droplets.

We are all about speed optimization of WordPress and this one small thing can slow down your Woocommerce / WordPress site.

By removing the add to cart URL from being indexed you will be able to Optimize Your Robots.txt for WordPress Speed and prevent useless URL’s from being index in the search engines.

You can also no index the following pages such as my account, admin, cart and checkout.

Lets face it, if you are trying to optimize your websites add to cart and checkout page for organic traffic then you a few beers short of a 6 pack.

Here is the snippet for Better Robots.txt Rules for WordPress. You can add this to your Robots.txt file which is usually installed in the public_html folder of your server.

User-agent: *
Disallow: /wp-admin/
Disallow: /*add-to-cart=*
Disallow: /cart/
Disallow: /checkout/
Disallow: /my-account/

seobetter ebook

SEOBetter: Step-by-step How to grow your traffic to 70,000 unique visitors in 11 weeks.

Get this eBook PDF for free (RRP $9.95 on Amazon Kindle), plus new updates and thoroughly tested online marketing techniques by subscribing to my newsletter.

sign up with facebook

You can also sign up to our newsletter with Facebook (quicker and easier)

Change The Slug of a WordPress Plugin’s Custom Post Type

If you are working on the SEO side of your WordPress website you may be using a plugin which has unfriendly SEO slug URL’s and you may want to update them. This seems like a hard task, though with this snippet you can change the slug of a plugin’s custom post type.

From this snippet you would want to update ‘program’ to your plugins current slug and ‘place’ to your desired slug.

CHANGE SLUGS OF CUSTOM POST TYPES - http://seobetter.com

function change_post_types_slug( $args, $post_type ) {

   /*item post type slug*/   
   if ( 'program' === $post_type ) {
      $args['rewrite']['slug'] = 'place';

   return $args;
add_filter( 'register_post_type_args', 'change_post_types_slug', 10, 2 );

CHANGE SLUGS OF TAXONOMIES, slugs used for archive pages

function change_taxonomies_slug( $args, $taxonomy ) {

   /*item category*/
   if ( 'program-category' === $taxonomy ) {
      $args['rewrite']['slug'] = 'locations';

   return $args;
add_filter( 'register_taxonomy_args', 'change_taxonomies_slug', 10, 2 );

How do i hide the WordPress header on the Woocommerce checkout page?

One way to reduce cart abandonment on your eCommerce website is to reduce or hide the distractions on the checkout page. The final step in the user buying funnel for your website is the checkout page. To optimize this you want to hide all of the clickable features so the customer is only focused on putting in their postal and payment information and clicking the checkout button.

This snippet will give you the option to hide the entire header of your Woocommerce checkout page along with the footer if you choose to remove that as well. We suggest using both but keeping the sites logo to keep the brand visible.

.woocommerce-page .site-footer, 
.woocommerce-page .cart-contents, 
.woocommerce-page .main-navigation,
.woocommerce-page .main-display,
    display: none !important;

If you enjoyed these PHP optimization snippets for Woocommerce then by all means sign up to our newsletter and we will invite you to our courses online when they launch with a BIG discount code.

We can help you out with things such as website promotion ideas and how to find low competition long tail keywords using free tools.

Make the WordPress WooCommerce category description show below products

You will want to add content to your Woocommerce category page for SEO reasons, so this snippet will let you move the category description to the bottom of the page on WordPress. This looks better so the customer does not have to read all of the text before they view the products on category pages.

Add this snippet to add the description below products on WooCommerce product category archives:

remove_action( 'woocommerce_archive_description', 'woocommerce_taxonomy_archive_description', 10 );

add_action( 'woocommerce_after_main_content', 'woocommerce_taxonomy_archive_description', 100 );

add_action( 'woocommerce_after_shop_loop', 'woocommerce_taxonomy_archive_description', 100 );

Leave a Reply

Your email address will not be published.