简体   繁体   中英

How to add Line Break for discount text on cart page of Woocommerce on Wordpress in function.php file

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');

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM