Skip to content

Instantly share code, notes, and snippets.

@jessepearson
jessepearson / functions.php
Last active August 12, 2021 10:52
Will clear out all the specified completed scheduled actions, 5000 at a time.
<?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 April 16, 2020 14:39
Allows the editing of the PayPal Standard Subscription ID even if it shouldn't be edited. Use at own risk.
<?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'] )
@jessepearson
jessepearson / functions.php
Last active December 2, 2019 18:53
Simple filter to add the 'partial-payment' status from Deposits to the order statuses that get pulled into default WooCommerce reports.
<?php // do not copy this line
/**
* Simple filter to add the 'partial-payment' status to the order statuses that get pulled into
* default WooCommerce reports.
*
* @param arr $statuses The original statuses.
* @return arr The updated statuses.
* @link https://gist.github.com/jessepearson/5b1cb1192488a2b4421bd214ccf17d45
*/
@jessepearson
jessepearson / functions.php
Last active October 23, 2019 11:04
Simple filter to change the 'no_shipping' value from 1 to 2 with PayPal Standard in WooCommerce when no shipping is needed.
<?php // do not copy this line
/**
* Simple filter to change the 'no_shipping' value from 1 to 2 with
* PayPal Standard in WooCommerce when no shipping is needed.
*
* @param arr $data The original data.
* @return arr The updated data.
* @link https://wordpress.org/support/topic/shipping-and-or-billing-address-not-being-sent-to-paypal-2/
* @link https://gist.github.com/jessepearson/3c258df272e73db875e901c0909a3554
@jessepearson
jessepearson / functions.php
Last active October 10, 2019 12:06
Simple filter to set the proper billing data for a customer in the post to PayPal Payflow.
<?php // do not copy this line
/**
* Simple filter to set the proper billing data for a customer in the post to PayPal Payflow.
*
* @param arr $data The original data.
* @return arr The updated data.
*/
function jp_fix_buyer_billing_data_payflow( $data ) {
@jessepearson
jessepearson / functions.php
Last active October 7, 2020 13:14
Adds the product link to low and out of stock emails in WooCommerce
<?php // do not copy this line
/**
* Adds the product link to low and out of stock emails in WooCommerce
* @param string $message Message stating low/out of stock.
* @param object $product The product's object the email is for.
* @return string The modified email with the link to edit the product.
*
* @link https://wordpress.org/support/topic/admin-stock-notification-emails/
* @link https://gist.github.com/jessepearson/701386d8ca5e4c84fc7cdf3d5d5391a3
<?php // do not copy this line
if( ! function_exists( 'mc_child_custom_woocommerce_states' ) ) {
function mc_child_custom_woocommerce_states( $states ) {
$states['LK'] = array(
'LK1001' => __( 'Colombo 1', 'woocommerce' ),
'LK1002' => __( 'Colombo 2', 'woocommerce' ),
'LK1003' => __( 'Colombo 3', 'woocommerce' ),
'LK1004' => __( 'Colombo 4', 'woocommerce' ),
@jessepearson
jessepearson / functions.php
Last active August 5, 2019 17:33
Turn off the block (Gutenberg) editor for the product post type in WooCommerce
<?php // do not copy this line
function jp_dectivate_gutenberg_for_products( $can_edit, $post_type ){
if( 'product' === $post_type ){
$can_edit = '';
}
return $can_edit;
}
add_filter( 'use_block_editor_for_post_type', 'jp_dectivate_gutenberg_for_products', 999, 2 );
@jessepearson
jessepearson / functions.php
Created August 2, 2019 13:10
Removes the payment instructions from the COD payment gateway in WooCommerce.
<?php // do not copy this line
/**
* Removes the payment instructions from the COD payment gateway in WooCommerce.
*/
function jp_custom_remove_instructions(){
if ( ! class_exists( 'WC_Payment_Gateways' ) ) {
return;
}
@jessepearson
jessepearson / functions.php
Last active December 28, 2023 20:50
Exclude category or tag from related products in WooCommerce
<?php // do not copy this line
/**
* Both functions below work the same, they just apply to categories and tags respectively.
* They exclude the defined IDs from being included in related products in WooCommerce.
*
* Note: The results are initially cached, so add this and then clear transients before saying it doesn't work.
*
* @link https://gist.github.com/jessepearson/dcf49d766cd1647465655fe9a14e51f2
* @param [array] $categories/$tags The array of categories or tags that are being used for related products.