Skip to content

Instantly share code, notes, and snippets.

View jrick1229's full-sized avatar
☠️

Joey Ricketts jrick1229

☠️
  • VA
  • 06:51 (UTC -04:00)
View GitHub Profile
@jrick1229
jrick1229 / wcs_my_custom_retry_rules.php
Last active November 29, 2018 16:50
Email customer immediately upon first failed payment
<?php
function wcs_my_custom_retry_rules( $default_retry_rules_array ) {
return array(
array(
'retry_after_interval' => DAY_IN_SECONDS / 2, // how long to wait before retrying
'email_template_customer' => 'WCS_Email_Customer_Payment_Retry', // email customer immediately upon first failed payment
'email_template_admin' => 'WCS_Email_Payment_Retry',
'status_to_apply_to_order' => 'pending',
'status_to_apply_to_subscription' => 'on-hold',
@jrick1229
jrick1229 / wcs_hide_unwanted_category.php
Last active November 29, 2018 17:19
Hide products by category from the shop page
<?php
/**
* Exclude products from a particular category on the shop page
*/
function wcs_hide_unwanted_category( $q ) {
$tax_query = (array) $q->get( 'tax_query' );
$tax_query[] = array(
'taxonomy' => 'product_cat',
'field' => 'slug',
@jrick1229
jrick1229 / wcs_add_cancel_button_on_subscriptions_page.php
Last active November 29, 2018 17:19
Add a 'Cancel' button to the Subscriptions page in the My Account area
<?php
function wcs_add_cancel_button_on_subscriptions_page($subscription) {
$actions = wcs_get_all_user_actions_for_subscription( $subscription, get_current_user_id() );
if(!empty($actions)){
foreach ( $actions as $key => $action ){
if(strtolower($action['name']) == "cancel"){
$cancelLink = esc_url( $action['url'] );
echo "<a href='$cancelLink' class='button cancel'>".$action['name']."</a>";
}
@jrick1229
jrick1229 / wcs_add_renew_now_button_to_subscriptions_page.php
Last active November 29, 2018 17:19
Add a 'Renew Now' button to the Subscriptions page in the My Account area
<?php
function wcs_add_renew_now_button_to_subscriptions_page($subscription) {
$actions = wcs_get_all_user_actions_for_subscription( $subscription, get_current_user_id() );
if(!empty($actions)){
foreach ( $actions as $key => $action ){
if(strtolower($action['name']) == "renew now"){
$renewNowLink = esc_url( $action['url'] );
echo "<a href='$renewNowLink' class='button subscription_renewal_early'>".$action['name']."</a>";
}
@jrick1229
jrick1229 / wcs_add_change_payment_button_to_subscriptions_page.php
Last active November 29, 2018 17:19
Add a 'Change payment' button to the Subscriptions page in the My Account area
<?php
function wcs_add_change_payment_button_to_subscriptions_page($subscription) {
$actions = wcs_get_all_user_actions_for_subscription( $subscription, get_current_user_id() );
if(!empty($actions)){
foreach ( $actions as $key => $action ){
if(strtolower($action['name']) == "change payment"){
$changePaymentLink = esc_url( $action['url'] );
echo "<a href='$changePaymentLink' class='button change_payment_method'>".$action['name']."</a>";
}
@jrick1229
jrick1229 / standalone-add-to-cart-button.html
Created June 25, 2018 18:57
Add an add-to-cart button anywhere
<input type="button" onclick="location.href='http://your-site.com/cart/?add-to-cart=[product-ID]';" value="Buy Now" />
@jrick1229
jrick1229 / wcopc_do_not_empty_cart.php
Last active November 29, 2018 17:19
OPC - Don't empty cart when using 'product-list' template
<?php
add_filter( 'wcopc_not_empty_cart', '__return_true', 100 );
@jrick1229
jrick1229 / wcs_disable_report_cache_update.php
Last active November 29, 2018 17:18
Disable 'Reports' cache updates for higher volume sites (Subscriptions)
<?php
function wcs_disable_report_cache_update() {
$cached_report_classes = array(
'WC_Report_Subscription_Events_By_Date',
'WC_Report_Upcoming_Recurring_Revenue',
'WC_Report_Subscription_By_Product',
'WC_Report_Subscription_By_Customer',
);
foreach ( $cached_report_classes as $report_class ) {
@jrick1229
jrick1229 / remove_subscriptions_tab.php
Last active November 29, 2018 17:18
Disable 'Subscriptions' reports tab
<?php
add_filter( 'woocommerce_admin_reports', 'remove_subscriptions_tab', 13, 1 );
function remove_subscriptions_tab( $reports ) {
// unset the subscriptions tab
unset($reports['subscriptions']);
return $reports;
}
@jrick1229
jrick1229 / wcs_do_not_reduce_renewal_stock.php
Last active November 29, 2018 17:18
Don't reduce stock on renewal - Subscriptions
<?php
function wcs_do_not_reduce_renewal_stock( $reduce_stock, $order ) {
if ( function_exists( 'wcs_order_contains_renewal' ) && wcs_order_contains_renewal( $order ) ) { // Subscriptions v2.0+
$reduce_stock = false;
} elseif ( class_exists( 'WC_Subscriptions_Renewal_Order' ) && WC_Subscriptions_Renewal_Order::is_renewal( $order ) ) {
$reduce_stock = false;
}
return $reduce_stock;
}