为了账号安全,请及时绑定邮箱和手机立即绑定

获取函数内字符串的值

获取函数内字符串的值

PHP
红颜莎娜 2023-09-22 17:40:30
所以就有了这个函数: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。我已经尝试移动东西好几个小时了,但我感觉自己在撞墙。有任何想法吗?
查看完整描述

1 回答

?
偶然的你

TA贡献1841条经验 获得超3个赞

如您所见,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 content

ob_start();

print_r($pickup_or_delivery);

$pickup_or_delivery = ob_get_clean();


查看完整回答
反对 回复 2023-09-22
?
Helenr

TA贡献1780条经验 获得超3个赞

使用以下代码获取“服务类型”:

$service_type = rpress_get_service_type( $payment_id );


查看完整回答
反对 回复 2023-09-22
  • 1 回答
  • 0 关注
  • 85 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信