Skip to content

Instantly share code, notes, and snippets.

@bernattorras
Last active March 23, 2021 05:46
Show Gist options
  • Save bernattorras/cadf3b4b79d9756e281af574d4feb380 to your computer and use it in GitHub Desktop.
Save bernattorras/cadf3b4b79d9756e281af574d4feb380 to your computer and use it in GitHub Desktop.
Change the strings of the options generated by Subscribe All The Things plugin
<?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
return $none_string.' '. $price;
}
// Customize the default "subsription option" string based on product ID
add_filter('wcsatt_single_product_subscription_option_description', 'change_sat_option_description', 10, 6);
function change_sat_option_description($description, $sub_price_html, $has_price_filter, $force_subscription, $product, $subscription_scheme){
$product_id = $product->id;
if($product_id == '447'){
$description = "Subscribe and save 20%";
}
return $description;
}
// Customize the description of a subscription option in the cart based on product ID and the subscription option
add_filter('wcsatt_cart_item_options', 'change_sat_option_cart_description', 11, 4);
function change_sat_option_cart_description($options, $subscription_schemes, $cart_item, $cart_item_key){
if($cart_item['product_id']==447){
foreach($options as $key=>$option){
if($option['value']=='1_month_1'){ // change '1_month_1' with the subscription option you want to change
$options[1]['description'] = 'Subscribe and save 20%';
}
}
}
return $options;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment