Skip to content

Instantly share code, notes, and snippets.

View growdev's full-sized avatar
😎
Future's so bright...

Daniel Espinoza growdev

😎
Future's so bright...
View GitHub Profile
@growdev
growdev / add-to-existing-subscription.php
Created October 4, 2022 22:29
Only show Add to Existing on some products.
<?php
/**
* Form used for add to existing subscription from the single product page.
*
* @author Shop Plugins
* @category WooCommerce Subscriptions/Templates
* @version 2.0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
@growdev
growdev / functions.php
Created May 20, 2022 15:45
Send email when a customer adds an item to their WooCommerce Subscription with Toolbox for WC Subscriptions plugin.
<?php
/**
* Send an email notification when a customer adds an item to their subscription.
*
* @param WC_Subscription $subscription
* @param WC_Product $product
* @param int $quantity
*/
function sp_toolbox_notify_add( $subscription, $product, $quantity ) {
$to = ''; // recipient of the email
@growdev
growdev / add-to-existing-subscription.php
Created March 16, 2022 15:43
Add textbox to get subscription details
<?php
/**
* Form used for add to existing subscription from the single product page.
*
* @author Shop Plugins
* @category WooCommerce Subscriptions/Templates
* @version 2.0.1
*/
if ( ! defined( 'ABSPATH' ) ) {
@growdev
growdev / functions.php
Created February 9, 2022 16:57
Change Hour of Next Payment
<?php
add_filter('sp_next_payment_time_of_day','sp_next_payment_time_of_day_change',10);
function sp_next_payment_time_of_day_change( $time ) {
return '09:00:00';
}
@growdev
growdev / functions.php
Created July 26, 2021 23:34
Check Min/Max quantity for line items and stop save if it is over.
<?php
/**
* Hooked into `jgtb_allow_edit_qty_for_subscription`, this will check
* the new quantity of items in the subscription and allow/disallow the
* edit.
*
* @param string $allowed 'yes' or 'no'.
* @param \WC_Subscription $subscription Instance of current subscription.
* @return string 'yes' or 'no'.
@growdev
growdev / refund.php
Created June 14, 2021 21:10
Bulk Refund WooCommerce Orders using CSV file input.
<?php
/**
* Bulk Refund Orders
*
* This script expects a csv file with following columns:
* - Order ID 1002
* - Reason for refund 'Item was oversold.'
* - Amount to refund '34.56'
* - Refund payment true/false
* - Restock item true/false
@growdev
growdev / update_next_payment.php
Created February 16, 2021 17:05
Update next payment date for subscribers
<?php
/**
* Update next payment date for subscriptions.
* Run this script using WP CLI:
* $ wp eval-file update_next_payment.php
*/
$subs = [
// ids of subscriptions to update
];
@growdev
growdev / functions.php
Created August 14, 2020 00:50
Toolbox - Send email when customer skips next payment
<?php
/**
* Send an email notification when a customer skips a subscription shipment.
*
* @param $subscription
* @param $user_id
* @param $old_next_date
* @param $next_payment_date
*/
@growdev
growdev / functions.php
Created July 14, 2020 15:46
Add data to the Pushover New Order notification
<?php
/**
* Hook into Pushover send notification on new order and add something to the title from order.
*
* @hook 'wc_pushover_notify_new_order'
* @param $args
* @return mixed
*/
function sp_wc_pushover_notify_new_order( $args ) {
@growdev
growdev / functions.php
Created June 4, 2020 16:25
Toolbox - Remove input quantity from /my-account/subscriptions page
<?php
// Remove the list of products in a subscription with the quantity input
remove_action( 'woocommerce_my_subscriptions_after_subscription_id', 'Javorszky\Toolbox\add_list_of_items' );
// Re-add the list of products without the quantity input.
add_action( 'woocommerce_my_subscriptions_after_subscription_id', 'sp_add_list_of_items' );
function sp_add_list_of_items( $subscription ) {
echo '<ul>';
foreach ( $subscription->get_items() as $item_id => $item ) {