add_action( 'woocommerce_order_status_changed', 'wcpsr_twilio_sms_on_picked', 10, 4 ); function wcpsr_twilio_sms_on_picked( $order_id, $old_status, $new_status, $order ) { // Rå debug för att se vad som kommer in error_log( sprintf( 'DEBUG wcpsr (rå): order #%d ändrad från "%s" till "%s"', $order_id, $old_status, $new_status ) ); // Kontrollera att det verkligen är “picked” if ( 'picked' !== $new_status ) { error_log( 'DEBUG wcpsr: Ny status är inte "picked", avbryter.' ); return; } error_log( 'DEBUG wcpsr: Status är "picked", kör SMS-logiken…' ); // Hämta kundens telefonnummer $phone_number = $order->get_billing_phone(); if ( empty( $phone_number ) ) { error_log( 'DEBUG wcpsr: Inget telefonnummer angivet, avbryter.' ); return; } // Normalisera telefonnummer till E.164 (exempel för svenska nr) $raw = preg_replace( '/\D+/', '', $phone_number ); if ( strpos( $raw, '0' ) === 0 ) { $to = '+46' . substr( $raw, 1 ); } elseif ( strpos( $raw, '46' ) === 0 ) { $to = '+' . $raw; } elseif ( strpos( $raw, '0046' ) === 0 ) { $to = '+' . substr( $raw, 2 ); } else { $to = ( substr( $phone_number, 0, 1 ) === '+' ) ? $phone_number : '+' . $raw; } error_log( 'DEBUG wcpsr: Normaliserat telefonnummer: ' . $to ); // Sätt ihop länk till PDF-kvitto $order_key = $order->get_order_key(); $receipt_url = esc_url( add_query_arg( array( 'receipt_pdf' => $order_id, 'order_key' => $order_key, ), home_url( '/' ) ) ); $billing_name = $order->get_billing_first_name() ?: 'Kund'; $message = sprintf( "Hej %s! Din beställning #%s är nu plockad. Hämta ditt kvitto här: %s", $billing_name, $order->get_order_number(), $receipt_url ); // Twilio-uppgifter – ersätt med dina korrekta från Twilio Console $sid = 'ACxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; $from = '+4670YYYYYYY'; // Ditt Twilio-nummer i E.164-format error_log( 'DEBUG wcpsr: Skickar SMS – From=' . $from . ', To=' . $to . ', Body=' . $message ); $url = "https://api.twilio.com/2010-04-01/Accounts/{$sid}/Messages.json"; $response = wp_remote_post( $url, array( 'headers' => array( 'Authorization' => 'Basic ' . base64_encode( $sid . ':' . $token ) ), 'body' => array( 'From' => $from, 'To' => $to, 'Body' => $message ), 'timeout' => 20, ) ); if ( is_wp_error( $response ) ) { error_log( 'Twilio SMS-fel (WP_Error): ' . $response->get_error_message() ); } else { $code = wp_remote_retrieve_response_code( $response ); $body = wp_remote_retrieve_body( $response ); error_log( 'Twilio SMS-svar: HTTP ' . $code . ' – ' . $body ); if ( $code >= 400 ) { error_log( 'Twilio returnerade felkod: ' . $code ); } } } Butik - Halal Express
Choose your Delivery Location
Enter your address and we will specify the offer for your area.
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Jämför