Product Page: Customize Order and Text of Autoship Product Page Strings
In the Examples below, a dev customizes the order and content of the Autoship strings using Autoship string filters. See the filters that can be used and details to the examples below.
Trying to change the "Autoship" / "Autoship and Save" text?
See how to customize the Autoship Label text in the Autoship Cloud Settings > Options page in our helpful doc here.
Simple Product Filters
- autoship_discount_checkout_and_recurring_same (filter) - When Autoship Checkout Price & Autoship Recurring Price have the same discount relative to the WooCommerce Regular Price
- autoship_discount_checkout_and_recurring (filter) - When Autoship Checkout Price & Autoship Recurring Price have the different discounts relative to the WooCommerce Regular Price
- autoship_discount_checkout (filter) - When Autoship Recurring Price ONLY has discount relative to the WooCommerce Regular Price
- autoship_discount_recurring (filter) - When Autoship Checkout Price ONLY has discount relative to the WooCommerce Regular Price
- autoship_no_discount (filter) - When there is no discount for Autoship relative to the WooCommerce Regular Price
In the example below, the dev adds "+ Free Shipping!" to their simple product which has the same Autoship Checkout & Recurring price
function add_free_shipping_string_to_products ($output, $strings){ $strings['checkout_percentage_string'] .= ' + Free Shipping! ' ; $output = $strings['autoship_string'] . $strings['checkout_percentage_string'] . $strings['price_string']; return $output; } add_filter('autoship_discount_checkout_and_recurring_same', 'add_free_shipping_string_to_products', 10, 2);
Before Before: Strings display with the default content
After: Displays customized "+ Free Shipping!" text added the Autoship strings before the price
Variable Product Filter
- autoship_checkout_recurring_variable_discount_string_html (filter) - Used for all variable product Autoship strings, regardless of the relative discount
/** * Update HTML for the Autoship and Save Variation extended text * * @param string $html. HTML text. * @param object $product. The WC_Product_Variable object. * @param array $strings. Array with translated strings. * * @return string HTML output */ function my_checkout_recurring_variable_discount_string_html( $html, $product, $strings ) { ob_start();?> <span class="autoship-discount-label"> <span class="autoship-checkout-price"></span> <span class="autoship-save"><?php echo $strings['autoship_save_string']; ?></span> <span class="autoship-custom-percent-discount-str"></span> </span> <span class="autoship-no-discount-label"> <span class="autoship"><?php echo $strings['autoship_string']; ?></span> </span> <?php return ob_get_clean(); } add_filter( 'autoship_checkout_recurring_variable_discount_string_html', 'my_checkout_recurring_variable_discount_string_html', 10, 3 );
Before: Strings display in the default order
After: Now the Price string displays 1st!