Skip to content
Advertisement

Get the value of a string inside a function

so there’s this function:

function rpress_get_service_types() {
  $service_types = array(
    'delivery'  => __( 'Delivery', 'restropress' ),
    'pickup'    => __( 'Pickup', 'restropress' )
  );
  return apply_filters( 'rpress_service_type', $service_types );
}

That I would like to get the value from. Let’s say, is it 'delivery' or 'pickup'?

Then, I need to know if the product this whole code refers to is set as a 'pickup' or 'delivery' – each product is assigned to only one of these two values.

So, before I even try to validate if it matches one of these two values, I thought I’d print it out in the email I send as a test to myself… to see if it works.

The code below returns the value The order #2262 is ready for delivery!Arraytest on the emails I receive as a test:

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

As you can see, I placed the variable inside $message = 'The order #' .$payment_id. ' is ready for delivery!' .$pickup_or_delivery. 'test';

To sumarize: this code displays the words Array.

I’ve tried moving things arround for many hours and I feel I’m hitting myself against the wall. Any ideas?

Advertisement

Answer

Use following code to get “Service type” :

$service_type = rpress_get_service_type( $payment_id );
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement