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 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 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 wc_get_customer_renewal_orders_by_status($customer_id, $status) { | |
$args = array( | |
'post_type' => 'shop_order', | |
'post_status' => $status, | |
'order' => 'ASC', | |
'meta_query' => array( | |
array( |
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 | |
// Customize the default "one time option" string | |
add_filter('wcsatt_single_product_one_time_option_description', 'change_sat_one_time_option_description', 10, 6); | |
function change_sat_one_time_option_description($none_string, $product){ | |
// This line of code removes all modifications that Subscribe All The Things plugin makes on the product price string (like adding "or subscribe and get...") | |
WCS_ATT_Product_Price_Filters::remove( 'price_html' ); | |
$price = $product->get_price_html(); | |
// Return the default string + the price of the product |
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 | |
/** | |
* Parse an adititonal "product_qtty" attribute provided in the "woocommerce_one_page_checkout" shortcode to specify the default number of units that should be used in each product quantity field | |
* | |
* | |
* Example: [woocommerce_one_page_checkout template="pricing-table" product_ids="451,10,70" product_qtty="1,2,3"] | |
* Instructions: Add an additional shortcode attribute named "product_qtty" with the default units that each product will display in its quantity input. The values must be separated by commas (",") and must match the order of the products specified in the "product_ids" attribute (the first number will be the number of units of the first product, and so on) | |
* Note: This attribute is used to specify the default value of each product quantity field. It DOESN'T add these products to the cart automatically. The customer must do it instead. | |
*/ |
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 remove_switch_link( $switch_link, $item_id, $item, $subscription ) { | |
$product_to_check = 336; | |
if( $subscription->has_product( $product_to_check ) ){ | |
return ''; | |
} | |
return $switch_link; | |
} |
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 | |
add_filter('woocommerce_subscription_period_interval_strings', 'add_extra_period_intervals', 10, 1); | |
function add_extra_period_intervals($intevals){ | |
$max_intervals = 10; // The maximum number of intervals you want to display | |
$intervals = array( 1 => _x( 'every', 'period interval (eg "$10 _every_ 2 weeks")', 'woocommerce-subscriptions' ) ); | |
foreach ( range( 2, $max_intervals ) as $i ) { | |
$intervals[ $i ] = sprintf( _x( 'every %s', 'period interval with ordinal number (e.g. "every 2nd"', 'woocommerce-subscriptions' ), WC_Subscriptions::append_numeral_suffix( $i ) ); | |
} |
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 | |
// Check the "shipping to different address" checkbox on the Checkout page if the cart contains a gifted item | |
add_filter('woocommerce_ship_to_different_address_checked','check_shipping_if_gifting', 11, 1); | |
function check_shipping_if_gifting($val){ | |
foreach ( WC()->cart->cart_contents as $key => $item ) { | |
if ( '' !== WCSG_Cart::get_recipient_from_cart_item( $item ) ) { | |
return true; | |
} | |
} | |
return $val; |
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 | |
// Make sure that EU VAT Field is displayed on OPC pages (when the cart is empty) | |
function enable_eu_vat_field_opc_defualt( $default, $option, $passed_default ) { | |
if ( is_wcopc_checkout() ) { | |
return 'yes'; | |
} | |
return $default; | |
} | |
add_filter( 'default_option_woocommerce_eu_vat_number_b2b', 'enable_eu_vat_field_opc_defualt', 11, 3 ); |