获取函数内字符串的值

所以就有了这个函数:


function rpress_get_service_types() {

  $service_types = array(

    'delivery'  => __( 'Delivery', 'restropress' ),

    'pickup'    => __( 'Pickup', 'restropress' )

  );

  return apply_filters( 'rpress_service_type', $service_types );

}

我想从中获得价值。比方说,是'delivery'还是'pickup'?


然后,我需要知道整个代码引用的产品是否设置为 or 'pickup'-'delivery'每个产品仅分配给这两个值之一。


因此,在我尝试验证它是否与这两个值之一匹配之前,我想我应该将其打印在我发送给自己的测试电子邮件中......以查看它是否有效。


下面的代码返回The order #2262 is ready for delivery!Arraytest我作为测试收到的电子邮件的值:


function send_customer_purchase_notification_ready( $payment_id, $new_status ) {


    $pickup_or_delivery = rpress_get_service_types( $service_types );

    $order_status = rpress_get_option( $new_status );

    $check_notification_enabled = isset( $order_status['enable_notification'] ) ? true : false;


    if ( !empty( $payment_id ) && $check_notification_enabled && $new_status !== 'pending' && $new_status == 'ready' ) {                  

        $message = 'The order #' .$payment_id. ' is ready for delivery!' .$pickup_or_delivery. 'test';

        $to = 'email@gmail.com';

        $subject = "READY FOR PICKUP";

        $headers = ''; 

        //Here put your Validation and send mail

        $sent = wp_mail($to, $subject, strip_tags($message), $headers);

    }

}

add_action( 'rpress_update_order_status', 'send_customer_purchase_notification_ready' , 10, 2 );

正如你所看到的,我将变量放在里面$message = 'The order #' .$payment_id. ' is ready for delivery!' .$pickup_or_delivery. 'test';


总结一下:此代码显示单词Array。


我已经尝试移动东西好几个小时了,但我感觉自己在撞墙。有任何想法吗?


红颜莎娜
浏览 86回答 1
1回答

偶然的你

如您所见,rpress_get_service_types()将会返回一个数组,因此$pickup_or_delivery是一个数组。您不能将字符串The order #2262 is ready for delivery!..与数组连接起来。如果需要,您应该使用implode将数组转换为字符串,或者使用ob_get_clean获取缓冲区内容$pickup_or_delivery = rpress_get_service_types();// get the imploded version$pickup_or_delivery = implode(',', $pickup_or_delivery);// or get the buffer contentob_start();print_r($pickup_or_delivery);$pickup_or_delivery = ob_get_clean();

Helenr

使用以下代码获取“服务类型”:$service_type = rpress_get_service_type( $payment_id );
打开App,查看更多内容
随时随地看视频慕课网APP