Change number of product displayed in woocommerce

Add this code in you theme functions.php. Make a child theme if you are using someone else theme to avoid your changes being overwritten during the next update.

/**
 * Change number of products that are displayed per page (shop page)
 */
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; //Enter the number of products you want per page here
  return $cols;
}
https://docs.woocommerce.com/document/change-number-of-products-displayed-per-page/

Remove SKU from email

override email-order-items.php in your template and comment out the SKU line.

To remove SKU from invoice, override print-content.php (from the Print Invoice and Delivery Note for Woocommerce Plugin) and comment the content with the dt and dd element on line 199 and 200.

Adding a custom field in a product page

1- Add a custom field in the backend

/**
*Add a custom field in the product data section of Woocommerce product.
*/
function cf_create_custom_field(){
 $args= array(
  'id'=>'custom_text_field_title',
  'label'=>__('Custom Text Field Title','cf'),
  'class'=>'cf-custom-field',
  'desc_tip'=>true,
  'description'=>__('Enter the description of your custom text field','cf'),
 );
woocommerce_wp_text_input($args);

}
add_action('woocommerce_product_options_general_product_date','cf_create_cutom_field');

You can find the list of accepted parameters here: https://github.com/woocommerce/woocommerce/blob/master/includes/admin/wc-meta-box-functions.php

Source: https://pluginrepublic.com/add-custom-fields-woocommerce-product/

/**
*Save the custom field
*/
function cf_save_custom_field($post_id){
  $product=wc_get_product($post_id);
  $title=isset($_POST['custom_text_field_title'])?$_POST['custom_text_field_title']:'';
  $product->update_meta_data('custom_text_field_title',sanitize_text_field($title));
  $product->save();
}
add_action('woocommerce_process_product_meta','cf_save_custom_field');
/*
*Display custom field on  the front end
*/
function cf_display_custom_field(){
  global $post;
  //Check for the custom field value
  $product=wc_get_product($post->ID);
  $title=$product->get_meta('custom_text_field_title');
  if ($title){
   //Only display our field if we've got a value for the field title
   printf(
   '<div class="cf-custom-field-wrapper"><label for ="cf-title-field">%s</label><input type="text" id="cf-title-field" name="cf-title-field" value=""></div>',
   esc_html($title)
   );
  }
}
add_action('woocommerce_before_add_to_cart_button','cf_display_custom_field');

Remove base for category permalink in woocommerce

https://docs.woocommerce.com/document/removing-product-product-category-or-shop-from-the-urls/
TLDNR: Not advisable

I have this idea that longer URI path, or deeper “file hierarchy” would have a negative SEO impact. But recently John Mueller made a statement that URI length did not have any negative SEO impact. The most important thing is that your important page are easily accessible to the search engine, and probably to your customer too.

In this article, Search Engine Journal speaks about length and recommend to keep it short but it’s an extrapolation on what J. Mueller said regarding URI longer than 1000 characters may not be a good practice (which is different from: “the shorter, the better”).

https://www.searchenginejournal.com/googles-john-mueller-recommends-keeping-urls-under-1000-characters/318739/#:~:text=Google’s%20John%20Mueller%20recently%20stated,under%201%2C000%20characters%20in%20length.&text=With%20that%20said%2C%20it’s%20generally,than%20they%20need%20to%20be.

In a more recent tweet, John was clear about that point:

https://www.seroundtable.com/google-url-length-seo-28952.html

Given that woocommerce does not recommend to remove the product-category base from the permalinks and that there is no clear SEO SEO advantage to it, then there is no reason to implement this feature.

If anything you can implement the option to have the product category included in your product permalink for SEO purpose. Having the product category in your URL might help google identify which category your product belong to and helped it rank for those keywords.

Price Filter not working

Issue: the woocommerce price filter is not working.

Solution: The issue is likely due to a compatibility issue with your theme. To solve that, you will need to declare the theme woocommerce support and copy your page.php file content to a new file that you will call woocommerce.php. You will replace the loop by <?php woocommerce_content(); ?>.

You will also need to make sure woocommerce support is declared in your theme functions.php: add_theme_support( 'woocommerce' );

For more info on woocommerce theme development and support:

https://docs.woocommerce.com/document/woocommerce-theme-developer-handbook/
Integrate woocommerce in your theme

Sidebar not showing on product tag pages

Issue: The sidebar and by extension the sidebar widgets are not showing on your product tag page on your woocommerce site.

Solution: While investigating this issue I have come accross many suggestion to use the widget-logic plugin to solve this issue. Chances are that it won’t help as some code is preventing your sidebar to show on the product_tag page.

Check your page.php template. It might have condition checking if the page is a woocomerce category page or the shop page for better control .

Check if your template has a woocommerce.php file, if it doesn’t look for the page.php file.

Check for a condition such as

if (is_product_category()||is_shop() )

Check that this control the display of the sidebar for example you might see:

get_sidebar()

If you find that the condition checking the page type call the sidebar, bingo, just add an extra condition so that the same code apply to your product-tag pages:

is_product_tag()

If you need to adapt the display for certain tag only you can use:

is_product_tag('tag_name')

To summarize in case you have condition controlling the call to the sidebar make sure to add the is_product_tag() function. In our example it would look like this:

 if (is_product_category()||is_shop() ||  is_product_tag()  )

EU VAT ID for Woocommerce

Do you want to write your own VAT ID plugin for woocommerce?

Here are some useful link that will help you in this task and helped me succesfully add a custom VAT ID field in woocommerce checkout page. It checks if the VAT ID is valid and remove the VAT accordingly from the price:

1- Add a VAT ID field to the checkout page

https://www.wpdesk.net/blog/vat-eu-woocommerce/

Check the DIY part! You will need to edit the hook action with a proper hook so that the field display. https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/

2- Perform the VAT ID validation

https://www.ptmr.io/blog/php-vies-vat-number-validation-european-vat-id/

3- Exempt customer from TAX if the EU VAT check out.

https://businessbloomer.com/woocommerce-remove-tax-checkout-field-value-exists/

4- refresh the total on change