Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / functions.php
Last active February 14, 2024 11:15
This is a filter to disable Multi-Currency in WooCommerce Payments.
<?php // Do not copy this line.
// This is a filter to disable Multi-Currency in WooCommerce Payments.
add_filter(
'pre_option__wcpay_feature_customer_multi_currency',
function ( $pre_option, $option, $default ) {
return '0';
},
10,
3
@jessepearson
jessepearson / functions.php
Last active August 3, 2021 11:59
Use the `wcpay_multi_currency_available_currencies` filter to add another currency to WooCommerce Payments Multi-Currencies.
<?php // do not copy this line
add_filter(
'wcpay_multi_currency_available_currencies',
function ( $currencies ) {
$currencies[] = 'BTC';
sort( $currencies );
return array_unique( $currencies );
}
);
@jessepearson
jessepearson / functions.php
Last active November 20, 2023 08:01
Will clear out all completed scheduled actions. Can be modified to clear out other statuses, as well.
<?php // Do not copy this line.
/**
* Will clear out all the specified completed scheduled actions, 5000 at a time.
*/
function clear_woocommerce_scheduled_actions_20200609() {
global $wpdb;
$limit = 5000;
$actions_table = $wpdb->prefix . 'actionscheduler_actions';
@jessepearson
jessepearson / functions.php
Last active January 11, 2021 16:46
Allows to change up the name of the Distance Rate label for WooCommerce Distance Rate Shipping.
<?php // do not copy this line
/**
* Allows to change up the name of the Distance Rate label for WooCommerce Distance Rate Shipping.
*/
add_filter( 'woocommerce_shipping_method_add_rate_args', 'jp_woocommerce_shipping_method_add_rate_args_2021_01_11', 50, 2 );
function jp_woocommerce_shipping_method_add_rate_args_2021_01_11( $args, $package ) {
// Check to see if it's a distance rate method.
if ( false !== strpos( $args['id'], 'distance_rate' ) ) {
<?php // do not copy this line
add_action( 'woocommerce_checkout_update_order_review', 'set_vat_exempt_for_customer_20201104', 10 );
function set_vat_exempt_for_customer_20201104( $post_data ) {
if ( isset( $_POST['country'] )
&& isset( $_POST['state'] )
&& 'ES' === $_POST['country']
&& 'TF' === $_POST['state'] ) {
@jessepearson
jessepearson / functions.php
Last active October 12, 2022 05:59
Disables opening Terms and Conditions on WooCommerce Checkout page in an inline form and instead open in a new tab or window.
<?php // do not copy this line
/**
* Disables opening the Terms and Conditions page in an inline form on the Checkout page.
* The Terms and Conditions link will then open in a new tab/window.
*/
add_action( 'wp', function() {
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_checkout_privacy_policy_text', 20 );
remove_action( 'woocommerce_checkout_terms_and_conditions', 'wc_terms_and_conditions_page_content', 30 );
} );
@jessepearson
jessepearson / functions.php
Created July 16, 2020 11:40
Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
<?php // do not copy this line
/**
* Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
*
* It works by modifying the coupon data that is used when creating the new coupon in the cart. The data that is
* able to be applied can be found here: https://github.com/woocommerce/woocommerce/blob/4.3.0/includes/class-wc-coupon.php#L26-L50
* Any edits will make the automatically generated coupon behave like a coupon created under WooCommerce > Coupons.
*
* This example make it so that if either categories 24 or 25 are in the cart, the referral is then applied.
@jessepearson
jessepearson / functions.php
Last active January 27, 2021 12:25
Dequeue the JavaScript files from WooCommerce Square on all pages except the checkout page.
<?php // do not copy this line
/**
* Note: This has not been tested on a live site and is to be used at your own risk.
*
* This will dequeue the JavaScript files from WooCommerce Square on all pages except the checkout page.
*/
add_action( 'wp_enqueue_scripts', 'dequeue_wc_square_js_scripts_20200713', 999 );
function dequeue_wc_square_js_scripts_20200713() {
// Not needed in admin, and we want to keep in checkout
@jessepearson
jessepearson / functions.php
Last active July 2, 2020 14:13
If order notes are added via AutomateWoo, they do not have a user associated with them. This is an example of how to make it so a user is added to a note added by AW.
<?php // do not copy this line
/**
* Adds hook to the AutomateWoo order paid action to add a filter.
*/
add_action( 'automatewoo/order/paid_async', 'add_automatewoo_note_filter_20200702' );
function add_automatewoo_note_filter_20200702() {
add_filter( 'woocommerce_new_order_note_data', 'add_author_to_automatewoo_note_20200702' );
}
@jessepearson
jessepearson / functions.php
Created June 18, 2020 14:19
Attempts to remove all shutdown actions if file is being downloaded via WC.
<?php // only copy this line if needed
/**
* Attempts to remove all shutdown actions if file is being downloaded via WC.
*/
function remove_all_shutdown_actions_20200618() {
remove_all_actions( 'shutdown' );
}
add_action( 'woocommerce_download_file_redirect', 'remove_all_shutdown_actions_20200618', 1 );
add_action( 'woocommerce_download_file_xsendfile', 'remove_all_shutdown_actions_20200618', 1 );