Skip to content

Instantly share code, notes, and snippets.

@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 );
/**
@corsonr
corsonr / functions.php
Last active September 14, 2018 09:02
WooCommerce: set price to zero
<?php
function make_it_free() {
echo '<table class="variations" cellspacing="0">
<tbody>
<tr>
<td class="label"><label>Make this free!</label></td>
<td class="value">
<label><input type="checkbox" name="option_free" value="YES" /> Set price to zero</label>
</td>
</tr>
@corsonr
corsonr / functions.php
Created July 24, 2018 07:34
WooCommerce 360: slow down...
<?php // Do not include this if already open! Code goes in theme functions.php.
/*
* Slow down WooCommerce 360 images rotation.
*/
add_filter( 'wc360_js_playspeed', 'woo_slow_down360' );
function woo_slow_down360( $speed ) {
return 50;
}
@corsonr
corsonr / functions.php
Created July 13, 2018 09:06
WooCommerce: Add conditional checkout fields based on products in cart
<?php // Do not include this if already open! Code goes in theme functions.php.
/**
* Add fields to the checkout page based on products in cart.
*
* @how-to https://remicorson.com/?p=7871
* @author Remi Corson
* @testedwith WooCommerce 3.4.0
*/
@corsonr
corsonr / functions.php
Created June 29, 2018 08:17
WooCommerce Stripe: force customer creation in Stripe
<?php // Do not include this if already open! Code goes in theme functions.php.
/*
* Force customer creation process in Stripe.
*/
add_filter( 'wc_stripe_force_save_source', '__return_true' );
@corsonr
corsonr / oncefiller.user.js
Last active March 29, 2019 07:58
A8C - Once key field auto-filler
// ==UserScript==
// @name A8C - Once key field auto-filler
// @namespace http://automattic.com/
// @version 0.1
// @description Pre-fill Once fields
// @author Remi Corson
// @match https://<place_mc_url_here>/once/*
// @require http://code.jquery.com/jquery-latest.js
// @grant none
// ==/UserScript==
@corsonr
corsonr / README.md
Last active September 25, 2022 09:11
WooCommerce: remove products ordering dropdown select in shop page

Remove default ordering on WooCommerce Shop page

This snippet gives the ability to remove the default product sortering dropdown select on the shop page. You can place the code in functions.php.

@corsonr
corsonr / functions.php
Created April 9, 2018 12:42
WooCommerce: checkout page hook sample
<?php
add_filter( 'woocommerce_review_order_before_payment', 'add_my_checkout_section' );
function add_my_checkout_section() {
wc_print_notice( apply_filters( 'woocommerce_checkout_my_checkout_section', __( 'Want a phone call before you buy?', 'woocommerce' ) . ' <a href="#">' . __( 'Click here, we call you back!', 'woocommerce' ) . '</a>' ), 'notice' );
}
@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 / functions.php
Created April 3, 2018 11:36
Get WooCommerce order details
<?php
$order->get_data(); (not needed is using the code above)
$order_id = $order_data['id'];
$order_parent_id = $order_data['parent_id'];
$order_status = $order_data['status'];
$order_currency = $order_data['currency'];
$order_version = $order_data['version'];
$order_payment_method = $order_data['payment_method'];
$order_payment_method_title = $order_data['payment_method_title'];