Some WooCommerce Tricks for Ya'll
Here’s a few things I’ve had to do with WooCommerce recently. I thought I’d share. I’ll add some more stuff to this list if I continue to work with it.
1. Allow only one item in the cart
Put this in your functions.php or wrap it up in a little plugin:
<?php
add_filter( 'woocommerce_add_cart_item_data', 'woo_single_cart' );
function woo_single_cart( $cart_item_data ) {
global $woocommerce;
$woocommerce->cart->empty_cart();
return $cart_item_data;
}
?>
2. Remove inline style (border) from “Add To Cart” shortcode
<?php echo do_shortcode( '[add_to_cart id="' . get_the_ID() . '" style=""]' ); ?>
3. Skip the cart, go direct to checkout
For this I just grabbed the Direct Checkout Plugin. I’m a little unclear as to what to “pro” version does but the free version suited my needs.
Pair this with #1 to create a simplified, cartless, one-item-at-a-time WooCommerce solution. That’s basically what I was up to when I wrote this.
Cheers,
Ryan