Skip to content

Instantly share code, notes, and snippets.

View jrick1229's full-sized avatar
☠️

Joey Ricketts jrick1229

☠️
  • VA
  • 21:46 (UTC -04:00)
View GitHub Profile
<?php
function eg_remove_my_subscriptions_button( $actions, $subscription ) {
$product_id = 228; // Update with correct product ID
if ( $subscription->has_product( $product_id ) ) {
foreach ( $actions as $action_key => $action ) {
switch ( $action_key ) {
case 'change_payment_method': // Hide
// case 'change_address': // Hide
// case 'switch': // Hide
<?php
add_action( 'woocommerce_customer_changed_subscription_to_cancelled', 'customer_skip_pending_cancellation' );
/**
* Change 'pending-cancel' status directly to 'cancelled'.
*
* @param WC_Subscription $subscription
*/
function customer_skip_pending_cancellation( $subscription ) {
if ( 'pending-cancel' === $subscription->get_status() ) {
@jrick1229
jrick1229 / wc_cancelled_order_add_customer_email.php
Last active March 31, 2022 15:09
Add customer email to Cancelled Order recipient list
<?php
/*
* Add customer email to Cancelled Order recipient list
*/
function wc_cancelled_order_add_customer_email( $recipient, $order ){
return $recipient . ',' . $order->billing_email;
}
add_filter( 'woocommerce_email_recipient_cancelled_order', 'wc_cancelled_order_add_customer_email', 10, 2 );
@jrick1229
jrick1229 / wcs_is_sub_active_notice.php
Last active September 15, 2019 15:05
Check if a subscription is active by displaying an admin notice. (for testing only)
<?php
function wcs_is_sub_active_notice() {
$sub_id = 445;
if ( wcs_get_subscription( $sub_id ) ) {
if ( wcs_get_subscription( $sub_id )->get_status() == 'active' ) {
$class = 'notice notice-error';
$message = __( '445 is ACTIVE', 'sample-text-domain' );
@jrick1229
jrick1229 / customer_recipient_cancelled_subscription.php
Last active November 29, 2018 17:21
Add customer to the cancelled subscription email as a recipient.
<?php
function add_customer_to_cancelled_subscription_email( $recipient, $order ) {
// Bail on WC settings pages since the order object isn't yet set yet
// Not sure why this is even a thing, but shikata ga nai
$page = $_GET['page'] = isset( $_GET['page'] ) ? $_GET['page'] : '';
if ( 'wc-settings' === $page ) {
return $recipient;
}
@jrick1229
jrick1229 / hide_cancel_button.php
Last active November 29, 2018 16:52
Hide the 'Cancel' button from the My Account page with Subscriptions
<?php
function eg_remove_my_subscriptions_button( $actions, $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 ] );
break;
default:
error_log( '-- $action = ' . print_r( $action, true ) );
@jrick1229
jrick1229 / wc_increase_variation_threshold.php
Last active February 18, 2022 14:41
Increase variation threshold from switching to AJAX to 500
<?php
function wc_increase_variation_threshold() {
return 500;
}
add_filter( 'woocommerce_ajax_variation_threshold', 'wc_increase_variation_threshold' );
@jrick1229
jrick1229 / wcs_custom_frequency.php
Last active March 1, 2023 21:54
Add an extra billing interval to WooCommerce Subscriptions
<?php
function wcs_custom_frequency( $intervals ) {
// change the $custom_frequency variable numerical value to what you'd like to add.
$custom_frequency = 50;
$intervals[$custom_frequency] = sprintf( __( 'every %s', 'my-text-domain' ), WC_Subscriptions::append_numeral_suffix( $custom_frequency ) );
return $intervals;
}
add_filter( 'woocommerce_subscription_period_interval_strings', 'wcs_custom_frequency' );
@jrick1229
jrick1229 / wcs_redirect_to_cart.php
Last active November 29, 2018 16:51
Redirect customer to cart page when 'Mixed Checkout' is enabled and product is added to cart
<?php
function wcs_redirect_to_cart( $url ) {
// If product is of the subscription type
if ( is_numeric( $_REQUEST['add-to-cart'] ) && WC_Subscriptions_Product::is_subscription( (int) $_REQUEST['add-to-cart'] ) ) {
// Redirect to cart instead
$url = WC()->cart->get_cart_url();
}
return $url;
}
@jrick1229
jrick1229 / disable_user_role_change.php
Last active November 29, 2018 16:51
WCS - Don't change user role when subscribing
<?php
add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );