Skip to content

Instantly share code, notes, and snippets.

@daigo75
daigo75 / wc-allow-specific-products-in-cart.php
Created November 23, 2019 16:21
WooCommerce - Allow specific products in cart (WC 3.x)
/**
* Restricts which products can be added to the cart at the same time.
* Version for WooCommerce 3.x and later.
*
* HOW TO USE THIS CODE
* 1. Add the code to the bottom of your theme's functions.php file (see https://www.skyverge.com/blog/add-custom-code-to-wordpress/).
* 2. Set the IDs of the products that are allowed to be added to the cart at the same time.
* 3. Amend the message displayed to customers when products are unavailable after the specified
* products have been added to the cart (see function woocommerce_get_price_html(), below).
*
@daigo75
daigo75 / dateFormat.js
Last active October 31, 2019 22:53 — forked from micah1701/dateFormat.js
Replicate PHP's native date() formatting in JavaScript for many common format types
/**
* Return a formated string from a date Object mimicking PHP's date() functionality
*
* format string "Y-m-d H:i:s" or similar PHP-style date format string
* date mixed Date Object, Datestring, or milliseconds
*
*/
function date_format(format,date){
if(!date || date === "")
@daigo75
daigo75 / woocommerce-restrict-cart-product-combinations.php
Last active July 10, 2023 21:12
WooCommerce – Only allow certain product combinations in cart
// Step 1 - Keep track of cart contents
add_action('wp_loaded', function() {
// This variable must be global, we will need it later. If this code were
// packaged as a plugin, a property could be used instead
global $allowed_cart_items;
// We decided that products with ID 737 and 832 can go together. If any of them
// is in the cart, all other products cannot be added to it
$restricted_cart_items = array(
737,
832,
@daigo75
daigo75 / gateway-gestpay-starter.php
Last active April 6, 2020 21:06
WooCommerce Gestpay - Fixes and improvements for multi-currency environments
<?php
/*
Plugin Name: WooCommerce GestPay Starter
Plugin URI: http://wordpress.org/plugins/woocommerce-gestpay/
Description: Estende WooCommerce fornendo il gateway di pagamento GestPay Starter di Banca Sella.
Version: 20150930
Author: Mauro Mascia (baba_mmx)
Author URI: http://www.mauromascia.com
License: GPLv2
Support: info@mauromascia.com
<?php
/**
* Earnings / Sales Stats
*
* @package EDD
* @subpackage Classes/Stats
* @copyright Copyright (c) 2015, Pippin Williamson
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.8
*/
@daigo75
daigo75 / woocommerce_custom_product_price_cache_key2.php
Last active April 18, 2017 08:53
WooCommerce 2.4 – Price cache workaround - Disable cache
// This code is no longer required as of WooCommerce 2.5
/**
* Disables the product price cache. This function looks for the cache key
* that is about to be retrieved by WooCommerce, and deletes the cached data
* associated to it.
*
* IMPORTANT
* This function can have an impact on WooCommerce's performance, and it
* should not be used unless necessary.
*
@daigo75
daigo75 / woocommerce_custom_product_price_cache_key1.php
Last active November 5, 2018 12:15
WooCommerce 2.4 – Price cache workaround - Dynamic key
/**
* Alters the key used to store cached prices. This code snippet allows
* to use dynamic cache keys, thus making it possible to store multiple
* sets of prices in the cache.
* You can add this code to the functions.php file in your child theme
* folder, or to a custom plugin.
*
* @param array cache_key_args The arguments that form the cache key.
* @param WC_Product product The product for which the key is being generated.
* @param bool display Indicates if the prices are being retrieved for display
@daigo75
daigo75 / class-wc-admin-report.php
Created March 25, 2015 17:16
WC_Admin_Report - Improved support for INNER, LEFT and RIGHT JOIN (ref. https://github.com/woothemes/woocommerce/issues/7818)
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Admin Report
*
* Extended by reports to show charts and stats in admin.
@daigo75
daigo75 / gist:5141929
Last active December 14, 2015 20:09 — forked from linc/gist:700805
<?php
/**
* @copyright Vanilla Forums Inc.
* @license GNU GPL2
*/
/**
* Instantiating this class will store current user's ID from cookie as $this->UserID.
*
* Usage