Skip to content

Instantly share code, notes, and snippets.

@NickGreen
NickGreen / delivery_date.php
Created March 20, 2020 23:16
Add Delivery Date to Order Export CSV
<?php
/**
* Plugin Name: Add delivery date to export
* Plugin URI:
* Description:
* Version: 1.0
* Author:
* Author URI:
**/
@NickGreen
NickGreen / get_subs_by_products.php
Last active March 9, 2020 18:17
Getting subs for known product IDs
<?php
// for troubleshooting specific site.
add_action( 'wp', 'get_subs_by_products' );
function get_subs_by_products() {
$product_ids = array(39002, 39001, 27181, 26017, 73821, 4178);
$subscriptions = wcs_get_subscriptions( array( 'product_id' => $product_ids, 'subscriptions_per_page' => -1, 'subscription_status' => array( 'wc-active', 'wc-on-hold' ) ) );
$number_of_subs = count($subscriptions);
@NickGreen
NickGreen / username_email.php
Last active February 27, 2020 00:09
Create username from email, just using the part before the "@"
<?php
add_filter( 'woocommerce_new_customer_data', 'customer_username_based_on_email', 20, 1 );
function customer_username_based_on_email( $new_customer_data ){
// get the first billing name
if(isset($_POST['billing_email'])) $billing_email = $_POST['billing_email'];
if( ! empty($billing_email) && ! in_array( $_POST['billing_email'] ) ){
// Replacing 'user_login' in the user data array, before data is inserted
@NickGreen
NickGreen / add_recipient_sub_expired_email.php
Last active November 22, 2021 02:19
Send to customer and 'CC' the admin on sub expired emails
<?php
/**
* Plugin Name: Sub Expired Email Send to Customer
* Plugin URI:
* Description:
* Version: 1.0
* Author:
* Author URI:
**/
@NickGreen
NickGreen / ipn.php
Created February 15, 2020 23:01
Print all IPN data to PP standard logs
<?php
add_action( 'valid-paypal-standard-ipn-request', 'test_handle_paypal_ipn_and_record_response', - 1 );
function test_handle_paypal_ipn_and_record_response( $posted ) {
WC_Gateway_Paypal::log( 'Data collected from IPN' . wc_print_r( $posted, true ) );
}
@NickGreen
NickGreen / points-db-export.php
Created January 18, 2020 02:40
export Points and Rewards custom table to CSV
<?php
//DB details
$dbHost = 'localhost';
$dbUsername = 'root';
$dbPassword = 'root';
$dbName = 'local';
$dbPrefix = 'wp';
//Create connection and select DB
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
@NickGreen
NickGreen / remove_cancel_gifted_subs.php
Created January 6, 2020 21:49
Remove 'cancel' button for gifted subscriptions only.
<?php
function remove_cancel_gifted_subs( $actions, $subscription ) {
if ( WCS_Gifting::is_gifted_subscription( $subscription ) ) {
foreach ( $actions as $action_key => $action ) {
switch ( $action_key ) {
case 'cancel': // Hide "Cancel" button on subscriptions that are "active" or "on-hold"?
unset( $actions[ $action_key ] );
@NickGreen
NickGreen / prevent_item_removal.php
Last active January 9, 2020 22:28
Prevent items from being removed from subscription
<?php // don't copy this line
add_filter( 'wcs_can_items_be_removed', '__return_false' );
@NickGreen
NickGreen / edit_all_orders.php
Last active December 11, 2019 22:58
Allow all orders to be edited
<?php
add_filter( 'wc_order_is_editable', 'wc_make_all_orders_editable', 12, 2 );
function wc_make_all_orders_editable( $is_editable, $order ) {
return true;
}
@NickGreen
NickGreen / exclude_recurring_from_coupons.php
Last active December 10, 2019 23:53
Remove any product coupons from products in the cart, that have a recurring scheme applied to it from All Products for WooCommerce Subscriptions
<?php
// Set the product discount amount to zero if it has a recurring scheme
add_filter( 'woocommerce_coupon_get_discount_amount', 'zero_discount_for_excluded_products', 12, 5 );
function zero_discount_for_excluded_products( $discount, $discounting_amount, $cart_item, $single, $coupon ){
if ( false != ( $cart_item[ 'wcsatt_data' ][ 'active_subscription_scheme' ] ) )
$discount = 0;