1

This is my code below and I've tried \n
'\n' '
' but nothing worked. I want to have two lines or paragraphs with First Line and Second Line in the discount line on the cart page

function prefix_add_discount_line( $cart ) {
  $chosen_methods = WC()->session->get( 'chosen_shipping_methods' );
  $chosen_shipping_no_ajax = $chosen_methods[0];
  if ( 0 === strpos( $chosen_shipping_no_ajax, 'local_pickup' ) ) {

    // Define the discount percentage
    $discount = $cart->subtotal * 0.15;
    // Add your discount note to cart
    $cart->add_fee( __( 'First Line (Second line)', 'yourtext-domain') , -$discount );
  }
}
add_action( 'woocommerce_cart_calculate_fees', 'prefix_add_discount_line');
Gokul
  • 11
  • 4

1 Answers1

1

You're looking for PHP_EOL

PHP_EOL is ostensibly used to find the newline character in a cross-platform-compatible way

$cart->add_fee( __( 'First Line' . PHP_EOL . '(Second line)', 'yourtext-domain') , -$discount );

Learn more

amarinediary
  • 4,930
  • 4
  • 27
  • 45