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 | |
// Extend the subscription period intervals to a custom number | |
function eg_extend_subscription_period_intervals( $intervals ) { | |
$max_intervals = 30; // 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 ) ); | |
} | |
return $intervals; | |
} |
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 | |
// Log Subscription status changes | |
add_filter( 'woocommerce_subscription_status_updated', 'log_sub_status_changes', 10, 3 ); | |
function log_sub_status_changes( $subscription, $new_status, $old_status ) { | |
$logger = new WC_Logger(); | |
$subscription_id = $subscription->get_id(); | |
$sub_user = $subscription->get_user_id(); | |
switch ( $new_status ) { |
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 | |
add_action( 'template_redirect', 'clear_cart_when_loading_page' ); | |
function clear_cart_when_loading_page() { | |
$page_id = 124; | |
if ( is_page( $page_id ) ) { | |
WC()->cart->empty_cart(); | |
// Uncomment the next lines if you want to add a product to the cart automatically | |
// $product_id = 1098; | |
// WC()->cart->add_to_cart( $product_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 | |
// 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 ); |
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 | |
// 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 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 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 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 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 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( |
NewerOlder