Skip to content

Instantly share code, notes, and snippets.

@UltimateWoo
UltimateWoo / uw-wc-cart-checkout-totals-new-row.php
Created January 27, 2018 16:25
Add new table row to WooCommerce cart/checkout totals
<?php
add_action( 'woocommerce_cart_totals_after_order_total', 'uw_display_cart_totals_after' );
add_action( 'woocommerce_review_order_after_order_total', 'uw_display_cart_totals_after' );
/**
* Pulls in cart totals and adds a new table row to the cart/checkout totals
*
* @author UltimateWoo - https://www.ultimatewoo.com
*/
function uw_display_cart_totals_after() {
@UltimateWoo
UltimateWoo / woocommerce-custom-product-tabs.php
Last active March 28, 2019 12:06
Adding custom product tabs in WooCommerce
<?php
/**
* Add a custom tab to WooCommerce products
*
* @param (array) $tabs - Registered tabs
* @return (array) $tabs - Updated array of tabs
*
* @author UltimateWoo <www.ultimatewoo.com>
*/
@UltimateWoo
UltimateWoo / wc-product-cat-genesis-force-layout.php
Created November 30, 2017 19:06
Force Genesis Layout on WooCommerce Product Category Archives
<?php
/**
* Sidebar-Content Layout on Product category archives
*
* @author UltimateWoo <www.ultimatewoo.com>;
*/
function ultimatewoo_wc_product_cat_genesis_layout() {
if ( is_tax( 'product_cat' ) ) {
return 'sidebar-content';
@UltimateWoo
UltimateWoo / functions.php
Last active November 22, 2017 16:42
WooCommerce Product Slider After Posts in Genesis Framework
<?php
/**
* Retrieve top selling products
*
* @param (int) $posts_per_page - Number of products to retrieve
* @return (array) Product posts
* @author UltimateWoo https://www.ultimatewoo.com
*/
function uw_woocommerce_get_top_selling_products( $posts_per_page = 5 ) {
@UltimateWoo
UltimateWoo / active-woocommerce-subscription.php
Created December 28, 2015 22:33
Check if the current user has an active WooCommerce subscription
<?php
/**
* Check if the current user has an active subscription.
* Redirect the user if no active subscription and the current post is a singule forum.
* This code should not be copied and pasted as is. It is only to demonstrate the wcs_user_has_subscription() function.
*
* wcs_user_has_subscription( $user_id = 0, $product_id = '', $status = 'any' )
* @param int (optional) The ID of a user in the store. If left empty, the current user's ID will be used.
* @param int (optional) The ID of a product in the store. If left empty, the function will see if the user has any subscription.
@UltimateWoo
UltimateWoo / custom-country-states-woocommerce.php
Created September 13, 2015 21:52
Add states to countries that do not include states in WooCommerce core
<?php
/**
* Add custom states to country in WooCommerce (Ex: Nigeria)
*/
add_filter( 'woocommerce_states', 'NG_woocommerce_states' );
function NG_woocommerce_states( $states ) {
$states['NG'] = array(
'SS' => __( 'Some State', 'woocommerce' ),
@UltimateWoo
UltimateWoo / reposition-points-rewards-my-account-table.php
Created July 11, 2015 16:27
Reposition WooCommerce Points and Rewards table on My Account page
<?php
/**
* Reposition the points table, generated by the Points and Rewards module, from the top to the bottom of the My Account page.
* @author UltimateWoo
* @link https://www.ultimatewoo.com/how-to-reposition-woocommerce-points-and-rewards-account-table/
*/
remove_action( 'woocommerce_before_my_account', 'woocommerce_points_rewards_my_points' );
add_action( 'woocommerce_after_my_account', 'woocommerce_points_rewards_my_points' );
@UltimateWoo
UltimateWoo / custom-woocommerce-loop.php
Created March 21, 2015 21:20
Custom query and loop for WooCommerce
<?php
if ( is_shop() || is_product_category() || is_product_tag() ) { // Only run on shop archive pages, not single products or other pages
// Products per page
$per_page = 24;
if ( get_query_var( 'taxonomy' ) ) { // If on a product taxonomy archive (category or tag)
$args = array(
@UltimateWoo
UltimateWoo / woocommerce-conditional-upsells.php
Created December 28, 2014 19:38
WooCommerce Conditional Upsells
<?php
/*
Plugin Name: WooCommerce Conditional Upsells
Plugin URI: http://www.ultimatewoo.com/woocommerce-conditional-upsells
Description: This is a fork of another Gist that we have put into plugin format. Define a list of Upsell products and a list of Required products. Upsells will be shown as an option to add to cart when all required products are currently in cart. They'll also be removed when a required product is removed.
Version: 1.0
Author: UltimateWoo
Author URI: http://www.ultimatewoo.com/