Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / functions.php
Last active May 17, 2021
Will clear out all completed scheduled actions. Can be modified to clear out other statuses, as well.
View functions.php
<?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 Jan 11, 2021
Allows to change up the name of the Distance Rate label for WooCommerce Distance Rate Shipping.
View functions.php
<?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' ) ) {
View set_vat_exempt_for_customer_20201104.php
<?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 Jan 27, 2021
Disables opening Terms and Conditions on WooCommerce Checkout page in an inline form and instead open in a new tab or window.
View functions.php
<?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 Jul 16, 2020
Allows for modifying the coupon that is created when AutomateWoo Refer A Friend is used.
View functions.php
<?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 Jan 27, 2021
Dequeue the JavaScript files from WooCommerce Square on all pages except the checkout page.
View functions.php
<?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 Jul 2, 2020
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.
View functions.php
<?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 Jun 18, 2020
Attempts to remove all shutdown actions if file is being downloaded via WC.
View functions.php
<?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 );
@jessepearson
jessepearson / functions.php
Last active Jan 27, 2021
Will clear out all the specified completed scheduled actions, 5000 at a time.
View functions.php
<?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';
$logs_table = $wpdb->prefix . 'actionscheduler_logs';
@jessepearson
jessepearson / functions.php
Last active Apr 16, 2020
Allows the editing of the PayPal Standard Subscription ID even if it shouldn't be edited. Use at own risk.
View functions.php
<?php // do not copy this line
/**
* Allows the editing of the PayPal Standard Subscription ID even if it shouldn't be edited.
* Use at own risk.
*/
function jp_allow_edit_of_pp_standard_sub_payment_20200416( $payment_meta, $subscription ) {
// Make sure that what we're going to edit exists.
if ( isset( $payment_meta['paypal'] )