Skip to content

Instantly share code, notes, and snippets.

View woogists's full-sized avatar

WooGists woogists

View GitHub Profile
@woogists
woogists / wc-change-number-of-related-products.php
Last active February 9, 2024 16:37
[Theming Snippets] Change number of related products output
@woogists
woogists / wc-payment-gateway-base.php
Created March 11, 2018 16:58
WooCommerce payment gateway plugin base
<?php
/*
Plugin Name: WooCommerce <enter name> Gateway
Plugin URI: http://woothemes.com/woocommerce
Description: Extends WooCommerce with an <enter name> gateway.
Version: 1.0
Author: WooThemes
Author URI: http://woothemes.com/
Copyright: © 2009-2011 WooThemes.
License: GNU General Public License v3.0
@woogists
woogists / wc-send-coupons-by-email.php
Last active January 25, 2024 20:15
Send coupons used in an order by email
/**
* Send an email each time an order with coupon(s) is completed
* The email contains coupon(s) used during checkout process
*
*/
function woo_email_order_coupons( $order_id ) {
$order = new WC_Order( $order_id );
if( $order->get_used_coupons() ) {
@woogists
woogists / wc-show-cart-contents-total-ajax.php
Last active December 31, 2023 10:08
[Theming Snippets] Show cart contents / total Ajax
/**
* Show cart contents / total Ajax
*/
add_filter( 'woocommerce_add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment' );
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
@woogists
woogists / woocommerce-usps-letters-and-envelopes.php
Last active December 29, 2023 19:51
USPS: Add Envelope as a service
<?php
/**
* Add letters and envelopes to international services.
*/
add_filter( 'wc_usps_services', function( $services ) {
$services['I_FIRST_CLASS']['services']['13'] = "First Class Mail&#0174; International Letters";
$services['I_FIRST_CLASS']['services']['14'] = "First Class Mail&#0174; International Large Envelope";
return $services;
@woogists
woogists / wc-remove-related-products.php
Last active December 29, 2023 16:55
[Theming Snippets] Remove related products output
@woogists
woogists / wc-product-addons-sold-individually.php
Created December 29, 2023 11:52
[Product Add-ons] Allow one instance of Sold Individually products in the cart, even if they have different add-ons selected
<?php
add_filter( 'woocommerce_add_to_cart_validation', 'check_if_product_exists_in_cart', 10, 2 );
function check_if_product_exists_in_cart( $is_valid, $product_id ) {
$product = wc_get_product( $product_id );
if ( $product->is_sold_individually() ) {
@woogists
woogists / woocommerce_add_to_cart_button_text.php
Last active December 6, 2023 09:57
Change the 'Add to Cart' button text on either single product or archives pages.
<?php
// Change add to cart text on single product page
add_filter( 'woocommerce_product_single_add_to_cart_text', 'woocommerce_add_to_cart_button_text_single' );
function woocommerce_add_to_cart_button_text_single() {
return __( 'Add to Cart Button Text', 'woocommerce' );
}
// Change add to cart text on product archives page
add_filter( 'woocommerce_product_add_to_cart_text', 'woocommerce_add_to_cart_button_text_archives' );
@woogists
woogists / wc-hide-all-shipping-if-free-shipping-is-available.php
Last active November 23, 2023 12:30
[General Snippets][Hide other shipping methods when “Free Shipping” is available] Hides all other shipping methods but free_shipping if it’s available. Compatible with Shipping zones.
/**
* Hide shipping rates when free shipping is available.
* Updated to support WooCommerce 2.6 Shipping Zones.
*
* @param array $rates Array of rates found for the package.
* @return array
*/
function my_hide_shipping_when_free_is_available( $rates ) {
$free = array();
foreach ( $rates as $rate_id => $rate ) {
@woogists
woogists / wc-new-account-notify-admin.php
Last active November 21, 2023 16:19
[General Snippets] Notify admin when a new customer account is created
/**
* Notify admin when a new customer account is created
*/
add_action( 'woocommerce_created_customer', 'woocommerce_created_customer_admin_notification' );
function woocommerce_created_customer_admin_notification( $customer_id ) {
wp_send_new_user_notifications( $customer_id, 'admin' );
}