This file contains hidden or 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 a product to clear the cart and add a specific product when a certain page is loaded | |
**/ | |
add_action( 'template_redirect', 'custom_add_product_to_cart' ); | |
function custom_add_product_to_cart() { | |
if(is_page(124)){ | |
$product_id = 1098; | |
WC()->cart->empty_cart(); |
This file contains hidden or 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 run some code when (before) the status of a subscription changes | |
**/ | |
add_action('woocommerce_subscription_pre_update_status', 'order_satus_changed', 100, 3); | |
function order_satus_changed($from, $to, $order ){ | |
// Run any code here | |
} |
This file contains hidden or 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 save the end of the trial date (on a custom meta field) when changing a subsription status to 'cancel', 'pending cancelation', 'switched' or 'expired' | |
**/ | |
add_action('woocommerce_subscription_pre_update_status', 'save_trial_end_meta', 10, 3); | |
function save_trial_end_meta($old_status, $new_status, $sub){ | |
if(in_array($new_status, array('cancelled', 'pending-cancel', 'switched', 'expired'))){ | |
$sub_id = $sub->get_id(); | |
$trial_end_date = $sub->get_date('trial_end'); |
This file contains hidden or 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 = ''; | |
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 | |
} | |
?> |