autoship_checkout_recurring_discount_string (function)

( src/product-page.php) Takes the (WooCommerce) $product_id and a boolean for if this is for a variable product or not. The function outputs the custom string after the Autoship radio button and includes the following filters to customize the discount strings:

  1. 'autoship_price_string' filter can be used to modify the current price separator (':') string portion.
  2. 'autoship_checkout_string' filter can be used to modify the current 'at checkout' string portion.
  3. 'autoship_concat_string' filter can be used to modify the current 'and' separator string portion.
  4. 'autoship_recurring_string' filter can be used to modify the current 'on future orders' string portion
  5. 'autoship_discount_checkout_and_recurring_same' filter which takes the current string, the string components array, and the product prices array. This filter allows developers to customize the message displayed after the Autoship radio option for when there is a checkout and recurring discount and both are the same.
  6. 'autoship_discount_checkout_and_recurring' filter which takes the current string, the string components array, and the product prices array. This filter allows developers to customize the message displayed after the Autoship radio option for when there is a checkout and recurring discount and both are not the same.
  7. 'autoship_discount_checkout' filter which takes the current string, the string components array, and the product prices array. This filter allows developers to customize the message displayed after the Autoship radio option for when there is a checkout discount only.
  8. 'autoship_discount_recurring' filter which takes the current string, the string components array, and the product prices array. This filter allows developers to customize the message displayed after the Autoship radio option for when there is a recurring discount only.
  9. 'autoship_no_discount' filter which takes the current string, the string components array, and the product prices array. This filter allows developers to customize the message displayed after the Autoship radio option for when there is no checkout or recurring discount.
  10. 'autoship_checkout_recurring_discount_string' filter which takes the current string, the string components array, and the product prices array. This filter allows developers to customize the message displayed after the Autoship radio option regardless of discount or not.
function autoship_checkout_recurring_discount_string( $product_id, $variable = false ){

  $product = wc_get_product( $product_id );
  $prices = autoship_get_product_prices( $product->get_id() );
  extract( $prices );

  if ( !$variable ){

    $strings['autoship_string']    = ( $autoship_percent_discount  || $autoship_percent_recurring_discount ) ?
    sprintf( '<span class="autoship-save">%s</span> ',
    apply_filters( 'autoship_radio_label', __( 'Autoship and Save', 'autoship' ),
    'yes', true, $product ) ) :
    sprintf( '<span class="autoship">%s</span>',
    apply_filters( 'autoship_radio_label', __( 'Autoship', 'autoship' ),
    'yes', false, $product ) );

    $strings['price_string']    = sprintf(
    '%s<span class="autoship-checkout-price">%s</span>',
    apply_filters( 'autoship_price_string', __( ': ', 'autoship' ) ),
    wc_price( $autoship_checkout_price ));

  } else {

    $strings['autoship_string'] = $strings['price_string'] = '';

  }

  $strings['checkout_percentage_string']   = sprintf(
    ' <span class="autoship-checkout-percent-discount">%s%%</span>',
    $autoship_percent_discount );

  $strings['checkout_string']     = sprintf(
    ' <span class="autoship-at-checkout">%s</span>',
    apply_filters( 'autoship_checkout_string', __( 'at checkout', 'autoship' ) ) );

  $strings['concat_string']       =
    apply_filters( 'autoship_concat_string', ' ' . __( 'and', 'autoship' ) );

  $strings['recurring_percentage_string']   = sprintf(
    ' <span class="autoship-recurring-percent-discount">%s%%</span>',
    $autoship_percent_recurring_discount );

  $strings['recurring_string']    = sprintf(
    ' <span class="autoship-recurring-percent-discount">%s</span>',
    apply_filters( 'autoship_recurring_string', __( 'on future orders', 'autoship' ) ) );

  $output  = $strings['autoship_string'];

  // If there's a discount at checkout & recurring
  if ( ( $autoship_percent_discount == $autoship_percent_recurring_discount ) && $autoship_percent_discount ) {

    $output  = $strings['autoship_string'];
    $output .= $strings['checkout_percentage_string'];
    $output .= $strings['price_string'];

    $output = apply_filters(
      'autoship_discount_checkout_and_recurring_same',
      $output,
      $strings,
      $prices
    );

  } elseif ( $autoship_percent_discount && $autoship_percent_recurring_discount ){

    $output  = $strings['autoship_string'];
    $output .= $strings['checkout_percentage_string'];
    $output .= $strings['checkout_string'];
    $output .= $strings['concat_string'];
    $output .= $strings['recurring_percentage_string'];
    $output .= $strings['recurring_string'];
    $output .= $strings['price_string'];

    $output = apply_filters(
      'autoship_discount_checkout_and_recurring',
      $output,
      $strings,
      $prices
    );

  } elseif ( $autoship_percent_discount ){

    $output  = $strings['autoship_string'];
    $output .= $strings['checkout_percentage_string'];
    $output .= $strings['checkout_string'];
    $output .= $strings['price_string'];

    $output = apply_filters(
      'autoship_discount_checkout',
      $output,
      $strings,
      $prices
    );

  } elseif ( $autoship_percent_recurring_discount ){

    $output  = $strings['autoship_string'];
    $output .= $strings['recurring_percentage_string'];
    $output .= $strings['recurring_string'];
    $output .= $strings['price_string'];

    $output = apply_filters(
      'autoship_discount_recurring',
      $output,
      $strings,
      $prices
    );

  } else {

    $output = apply_filters(
      'autoship_no_discount',
      $output,
      $strings,
      $prices
    );

  }

  return apply_filters(
  'autoship_checkout_recurring_discount_string',
  $output,
  $strings,
  $prices
  );

}