Skip to content

Instantly share code, notes, and snippets.

@maxrice
maxrice / remove-store-name.php
Created July 6, 2022 21:07
Remove store name from merchant_ref field for First Data Payeezy
<?php
// remove Store name from merchant_ref field for First Data Payeezy
add_filter( 'wc_payment_gateway_first_data_payeezy_credit_card_get_order_base', function( $order ) {
$order->description = sprintf( 'Order #%1$s', $order->get_order_number() );
return $order;
}, 1 );
@maxrice
maxrice / shorten-woo-rest-api-order-payment-method.php
Last active June 23, 2022 18:37
Remove the leading "woocommerce_" from the Woo REST API payment_method attribute
<?php
add_filter( 'woocommerce_rest_prepare_shop_order_object', function( $response ) {
// strip leading woocommerce_ from payment method
if ( ! empty( $response->data['payment_method'] ) ) {
$response->data['payment_method'] = str_replace( 'woocommerce_first_data_', '', $response->data['payment_method'] );
}
return $response;
@maxrice
maxrice / jilt-for-wc-watch-email.php
Last active November 8, 2018 22:33
Jilt for WooCommerce - watch an email input and automatically set the customer when populated
<?php
add_action( 'init', 'jilt_for_wc_add_custom_email_capture' );
function jilt_for_wc_add_custom_email_capture() {
if ( function_exists( 'wc_enqueue_js' ) ) {
ob_start();
?>
$(window).load(function() {
var opts = {
callback: function (value) {
@maxrice
maxrice / jilt-for-woocommerce-order-is-placed-filter.php
Created February 10, 2018 19:12
Jilt for WooCommerce - prevent pending orders placed with a certain payment gateway from being sent recovery emails
<?php
add_filter( 'wc_jilt_order_is_placed', function( $placed, $order ) {
return $placed || ( 'pending' == $order->get_status() && 'divido' == $order->get_payment_method() );
}, 10, 2 );
@maxrice
maxrice / jilt-for-wc-clear-persistent-carts.php
Last active June 2, 2019 09:00
Jilt for WooCommerce - Clear persistent carts for customers who signed up over 30 days ago
<?php
add_filter( 'woocommerce_debug_tools', function( $tools ) {
$tools['wc_jilt_clear_persistent_carts'] = array(
'name' => __( 'Clear Persistent Carts from customers who signed up over 30 days ago.', 'jilt-for-woocommerce' ),
'button' => __( 'Clear', 'woocommerce-plugin-framework' ),
'desc' => __( 'This tool will clear the persistent cart for all registered customers who signed up over 30 days ago.', 'jilt-for-woocommerce' ),
'callback' => 'wc_jilt_clear_persistent_carts'
);
return $tools;
@maxrice
maxrice / jilt-for-wc-force-individual-use-coupons.php
Created January 31, 2018 22:22
Jilt for WooCommerce - force individual use for coupons created by Jilt
<?php
add_filter( 'woocommerce_coupon_get_individual_use', function( $individual_use, $coupon ) {
if ( $coupon->meta_exists( 'jilt_discount_id' ) ) {
$individual_use = true;
}
return $individual_use;
}, 10, 2 );
@maxrice
maxrice / jilt-for-wc-disable-email-field-move.php
Created October 11, 2017 21:47
Jilt for WooCommerce - Disable moving the email field at checkout
<?php
add_action( 'init', function() {
if ( is_callable( 'wc_jilt' ) ) {
remove_filter( 'woocommerce_checkout_fields', array( wc_jilt()->get_checkout_handler_instance(), 'move_checkout_email_field' ), 1 );
}
}, 20 );
@maxrice
maxrice / jilt-for-wc-recovery-link-redirect-to-cart.php
Created October 10, 2017 03:04
Jilt for WooCommerce - Recovery link redirect to cart
@maxrice
maxrice / wc-customer-order-csv-export-add-order-customer-ip.php
Created December 7, 2015 22:05
WooCommerce Customer/Order CSV Export - add order customer IP column
<?php
// add customer IP column header
function wc_csv_export_add_customer_ip_column_header( $column_headers ) {
$new_headers = array(
'customer_ip' => 'customer_ip',
);
return array_merge( $column_headers, $new_headers );
@maxrice
maxrice / wc-auth-net-cim-save-payment-method-default-checked.php
Created August 3, 2015 16:08
WC Authorize.net CIM: On the payment form, default "securely save to account" checkbox to checked
<?php
// force the "securely save to account" checkbox to default to checked
function wc_auth_net_cim_save_payment_method_default_checked( $html, $form ) {
if ( empty( $html ) || $form->tokenization_forced() ) {
return $html;
}
return str_replace( 'type="checkbox"', 'type="checkbox" checked="checked"', $html );
}