[英]How to add Line Break for discount text on cart page of Woocommerce on Wordpress in function.php file
这是我下面的代码,我已经尝试过\n
'\n' '
'但没有任何效果。 我想在购物车页面的折扣行中有两行或两行,第一行和第二行
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');
您正在寻找PHP_EOL
PHP_EOL 表面上用于以跨平台兼容的方式查找换行符
$cart->add_fee( __( 'First Line' . PHP_EOL . '(Second line)', 'yourtext-domain') , -$discount );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.