Skip to content

Instantly share code, notes, and snippets.

View corsonr's full-sized avatar

Remi Corson corsonr

View GitHub Profile
@corsonr
corsonr / gist:81a67e71dca0e9bd18f3
Created March 19, 2015 09:26
WooCommerce: filter shipping packages
add_filter( 'woocommerce_cart_shipping_packages', 'bulky_woocommerce_cart_shipping_packages' );
function bulky_woocommerce_cart_shipping_packages( $packages ) {
// Reset the packages
$packages = array();
// Bulky items
$bulky_items = array();
$regular_items = array();
@corsonr
corsonr / gist:7640922
Created November 25, 2013 13:05
Limit Number of Products to Add to The Shop - WooCommerce
add_action( 'admin_head-post-new.php', 'woo_limit_products_creation' );
function woo_limit_products_creation() {
global $post_type;
global $wpdb;
$products_limit = 50; // Change this value
if( $post_type === 'product' ) {
@corsonr
corsonr / create-woocommerce-order-dynamically.php
Created April 4, 2017 10:03
Create a WooCommerce Order Dynamically
<?php
/*
* Create order dynamically
*/
add_action( 'woocommerce_before_checkout_form', 'create_order' );
function create_order() {
global $woocommerce;
@corsonr
corsonr / gist:3d0425deaa80c601d454
Last active August 9, 2023 17:49
WooCommerce: custom variations settings
<?php
// Add Variation Settings
add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
// Save Variation Settings
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
/**
* Create new fields for variations
@corsonr
corsonr / woo-restrict-ordersper-day.php
Last active July 6, 2023 02:39
WooCommerce - restrict number of orders per day
<?php
/**
* Plugin Name: Restrict Orders per Day for WooCommerce
* Plugin URI: https://remicorson.com
* Description: Put the shop into catalogue mode once number of orders per day is reached.
* Version: 0.1
* Author: Remi Corson, corsonr
* Author URI: https://remicorson.com
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
@corsonr
corsonr / functions.php
Last active July 4, 2023 08:14
Loop through WooCommerce order products
<?php
$count = 1;
foreach( $order->get_items() as $item_id => $line_item ){
$item_data = $line_item->get_data();
$product = $line_item->get_product();
$product_name = $product->get_name();
$item_quantity = $line_item->get_quantity();
$item_total = $line_item->get_total();
$metadata['Line Item '.$count] = 'Product name: '.$product_name.' | Quantity: '.$item_quantity.' | Item total: '. number_format( $item_total, 2 );
@corsonr
corsonr / jquery.ui.datepicker-fr.js
Created December 16, 2012 10:53
jQuery UI datepicker in French
/* French initialisation for the jQuery UI date picker plugin. */
/* Written by Keith Wood (kbwood{at}iinet.com.au) and Stéphane Nahmani (sholby@sholby.net). */
jQuery(function($){
$.datepicker.regional['fr'] = {
closeText: 'Fermer',
prevText: '&#x3c;Préc',
nextText: 'Suiv&#x3e;',
currentText: 'Aujourd\'hui',
monthNames: ['Janvier','Fevrier','Mars','Avril','Mai','Juin',
'Juillet','Aout','Septembre','Octobre','Novembre','Decembre'],
@corsonr
corsonr / Secure email shortcode
Created September 18, 2012 15:16
secure email shortcode
<?php
/* ------------------------------------------------------------------*/
/* SECURE EMAIL SHORTCODE */
/* ------------------------------------------------------------------*/
function xxx_secure_mail( $atts ) {
extract(
shortcode_atts( array(
"mailto" => '',
"txt" => ''
@corsonr
corsonr / rest_api_create_post.php
Created December 2, 2022 11:08
Introduction to the WordPress Rest API
<?php
// Set the endpoint and request method
$endpoint = '/wp/v2/posts';
$method = 'POST';
// Set the request body data
$body = array(
'title' => 'My new post',
'content' => 'This is the content of my new post.',
@corsonr
corsonr / functions.php
Created January 28, 2019 12:02
WooCommerce: display products discounted price in cart table
<?php
/*
* Display discounted products prices in the cart table.
*
* Modification of code provided here https://businessbloomer.com/woocommerce-display-cart-item-subtotal-coupon-discount/.
*/
add_filter( 'woocommerce_cart_item_subtotal', 'if_coupon_slash_item_subtotal', 99, 3 );
add_filter( 'woocommerce_cart_item_price', 'if_coupon_slash_item_subtotal', 99, 3 );
/**