This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Disable Automatic Payments when the cart only contains subscriptions with free trial (allowing customers to purchase the subscription without adding any payment information) | |
add_filter('option_woocommerce_subscriptions_turn_off_automatic_payments','disable_payment_gateways_on_trial_sub', 1); | |
function disable_payment_gateways_on_trial_sub($automatic_payments_off){ | |
if(!is_admin()){ | |
$all_trial = WC_Subscriptions_Cart::all_cart_items_have_free_trial(); | |
if($all_trial==1){ | |
// All items in the cart contain a free trial | |
return 'yes'; // Turn off automatic payments (disabling payment gateways) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Register new status | |
* Tutorial: http://www.sellwithwp.com/woocommerce-custom-order-status-2/ | |
**/ | |
function register_holding_shipment_order_status() { | |
register_post_status( 'wc-holding-shipment', array( | |
'label' => 'Holding shipment', | |
'public' => true, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to create pending renewal orders for given subscriptions | |
**/ | |
add_action( 'init', 'create_pending_orders_for_subscriptions' ); | |
function create_pending_orders_for_subscriptions(){ | |
$subscriptions = array(76,72); | |
foreach($subscriptions as $subscription_id){ | |
$subscription = wcs_get_subscription( $subscription_id ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to execute some code when a subscription is paid using Stripe gateway | |
**/ | |
add_action('woocommerce_scheduled_subscription_payment_stripe', 'renewal_notifier_stripe', 11, 2); | |
function renewal_notifier_stripe($total, $renewal_order){ | |
// Your custom functionality | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to execute some code when a subscription is paid | |
**/ | |
add_action('woocommerce_scheduled_subscription_payment', 'renewal_notifier', 11, 1); | |
function renewal_notifier($sub_id){ | |
// Your custom functionality | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to preserve custom URL parameters on OPC pages after adding a product to the cart | |
**/ | |
add_filter( 'woocommerce_add_to_cart_redirect', 'opc_keep_affiliate_arg', 11, 1 ); | |
function opc_keep_affiliate_arg( $url ) { | |
if ( ! is_ajax() && is_wcopc_checkout() ) { | |
$schema = is_ssl() ? 'https://' : 'http://'; | |
$url = explode('?', $schema . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to add extra month intervals to the subscription editor page | |
**/ | |
add_filter('woocommerce_subscription_period_interval_strings', 'add_extra_month_intervals', 10, 1); | |
function add_extra_month_intervals($intervals){ | |
foreach ( range( 7, 12 ) as $i ) { | |
$intervals[$i] = "every ".$i."th"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to redirect the customer to a custom 'thank you' page after placing an order | |
**/ | |
add_action( 'template_redirect', 'woo_custom_redirect_after_purchase' ); | |
function woo_custom_redirect_after_purchase() { | |
global $wp; | |
if ( is_checkout() && !empty( $wp->query_vars['order-received'] ) ) { | |
wp_redirect( ' http://localhost:8888/subscriptions/custom-thank-you-page/' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to redirect the customer to a the checkout page (or a custom page) after adding a product to the cart | |
**/ | |
add_filter ('woocommerce_add_to_cart_redirect', 'redirect_to_checkout'); | |
function redirect_to_checkout() { | |
return wc_get_checkout_url(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Function to disable the "Choose a new subscription" message when switching a subscription item | |
**/ | |
add_filter('woocommerce_add_notice', 'disable_switch_notice', 10, 1); | |
function disable_switch_notice( $message){ | |
if($message=="Choose a new subscription."){ | |
$message = ''; | |
} |
OlderNewer