WooCommerce 3.1.2: How to restore “add to cart” button in product category page

I noticed “add to cart” (or “select option” for variable products) buttons are no longer there with the most recent version of WooCommerce.
I checked content-product.php to see if the button was removed…it was not according to their template comment:

 * The template for displaying product content within loops
 * This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 * @see     https://docs.woocommerce.com/document/template-structure/
 * @author  WooThemes
 * @package WooCommerce/Templates
 * @version 3.0.0

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly

global $product;

// Ensure visibility
if ( empty( $product ) || ! $product->is_visible() ) {
<li <?php post_class(); ?>>
	 * woocommerce_before_shop_loop_item hook.
	 * @hooked woocommerce_template_loop_product_link_open - 10
	do_action( 'woocommerce_before_shop_loop_item' );

	 * woocommerce_before_shop_loop_item_title hook.
	 * @hooked woocommerce_show_product_loop_sale_flash - 10
	 * @hooked woocommerce_template_loop_product_thumbnail - 10
	do_action( 'woocommerce_before_shop_loop_item_title' );

	 * woocommerce_shop_loop_item_title hook.
	 * @hooked woocommerce_template_loop_product_title - 10
	do_action( 'woocommerce_shop_loop_item_title' );

	 * woocommerce_after_shop_loop_item_title hook.
	 * @hooked woocommerce_template_loop_rating - 5
	 * @hooked woocommerce_template_loop_price - 10
	do_action( 'woocommerce_after_shop_loop_item_title' );

	 * woocommerce_after_shop_loop_item hook.
	 * @hooked woocommerce_template_loop_product_link_close - 5
	 * @hooked woocommerce_template_loop_add_to_cart - 10
   	do_action( 'woocommerce_after_shop_loop_item' );

Regardless, the button is still not there so I added the button again in the current theme’s functions.php (since I wasn’t making any other overwrite):

//woocommerce - restore "add to cart" button in product category page
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 20 );

And voila, it’s back.

The same disappearance behavior was observed in multiple themes…so I’m suspecting something happened in WooCommerce plugin (as opposed to a theme-related bug).

WooCommerce 2.3.8 – how to set minimum order amount for a product

It’s not uncommon to be asked to implement minimum checkout requirements to WooCommerce Cart. The common requirements are:

  • Minimum Dollar Amount Per Order
  • Minimum Number of Products Per Order or Per Products

Luckily, there is a great tutorial for implementing these by Yojance Rabelo.

But the other day, I got a request to implement minimum dollar amount PER PRODUCT…not too common, but not never-heard-of either.

So I decided to tweak Yojance’s Minimum Dollar Per Order code to set minimum order amount for a product instead of for the entire order: Continue reading “WooCommerce 2.3.8 – how to set minimum order amount for a product”

Make PHP Mail() work in AWS EC2 – Ubuntu 14.04

AWS IP addresses can be problematic for setting an email server in an EC2 instance…even with right setup email sent from the IP address can be marked as spam.

So what to do with setting up SMTP for your web applications? One alternative is to use AWS SES service. I decided not to use SES, however, because 1) each email address or domain needs to be approved and 2) there is cost associated with number of email sent out. These aren’t too bad of the restrictions but I wanted something that JUST work without configuring every time I build a website.

I went with MSMTP to use my gmail account to send email message by default. I can also overwrite the smtp setting per linux account. So if I were to host sites that are not mine, they can use their own smtp setup.
Continue reading “Make PHP Mail() work in AWS EC2 – Ubuntu 14.04”

Problem with linking models containing multiple words in CakePHP

I had two models, “Example” and “ExampleModel”, linked with belongsTo – hasMany relationship.

The problem was, after baking, the dropdown selection for ExampleModel in Example’s add and view pages were totally blank. Yet, in the index page, the data is shown (which means that relationship is established correctly). Continue reading “Problem with linking models containing multiple words in CakePHP”

WooCommerce 2.1.9 cheatsheet – product listing page

How To Change Number Products Displayed Per Page

Insert the following code in your theme’s functions.php

// Display 40 products per page. 
add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 40;' ), 20 );

Continue reading “WooCommerce 2.1.9 cheatsheet – product listing page”

WooCommerce 2.1.9 cheatsheet – single product page

How To Remove Related Products

Add the following code to your theme’s functions.php

//remove related products from single product page
remove_action ( 'woocommerce_after_single_product_summary', 'woocommerce_output_related_products', 20);

Continue reading “WooCommerce 2.1.9 cheatsheet – single product page”