php - 自定义插件干扰订单“PHP”
问题描述
我有这个我想在我的 wordpress 中使用的定制插件,当我激活它时,它开始干扰订单后端,这意味着每当我想查看客户订购了什么产品时,我只能看到价格,但产品的图像未显示在 Woocommerce > 订单 > 单击订单。
<?php
function sms_notif_pending($order_id) {
// error_log("$order_id set to PENDING", 0);
sms_notif_order_status_updated($order_id, 'pending');
}
function sms_notif_failed($order_id) {
// error_log("$order_id set to FAILED", 0);
sms_notif_order_status_updated($order_id, 'failed');
}
function sms_notif_hold($order_id) {
// error_log("$order_id set to ON HOLD", 0);
sms_notif_order_status_updated($order_id, 'hold');
}
function sms_notif_processing($order_id) {
// error_log("$order_id set to PROCESSING", 0);
sms_notif_order_status_updated($order_id, 'processing');
}
function sms_notif_completed($order_id) {
//error_log("$order_id set to COMPLETED", 0);$
sms_notif_order_status_updated($order_id, 'completed');
}
function sms_notif_refunded($order_id) {
// error_log("$order_id set to REFUNDED", 0);
sms_notif_order_status_updated($order_id, 'refunded');
}
function sms_notif_cancelled($order_id) {
// error_log("$order_id set to CANCELLED", 0);
sms_notif_order_status_updated($order_id, 'cancelled');
}
function sms_notif_at_delivery($order_id) {
// error_log("$order_id set to CANCELLED", 0);
sms_notif_order_status_updated($order_id, 'at_delivery');
}
function sms_notif_at_reserved($order_id) {
// error_log("$order_id set to CANCELLED", 0);
sms_notif_order_status_updated($order_id, 'at_reserved');
}
function sms_notif_at_fitting($order_id) {
// error_log("$order_id set to CANCELLED", 0);
sms_notif_order_status_updated($order_id, 'at_fitting');
}
function sms_notif_shipping_progress($order_id) {
// error_log("$order_id set to CANCELLED", 0);
sms_notif_order_status_updated($order_id, 'shipping_progress');
}
add_action( 'woocommerce_new_order', 'sms_notif_pending');
add_action( 'woocommerce_order_status_pending', 'sms_notif_pending');
add_action( 'woocommerce_order_status_failed', 'sms_notif_failed');
add_action( 'woocommerce_order_status_on-hold', 'sms_notif_hold');
add_action( 'woocommerce_order_status_processing', 'sms_notif_processing');
add_action( 'woocommerce_order_status_completed', 'sms_notif_completed');
add_action( 'woocommerce_order_status_refunded', 'sms_notif_refunded');
add_action( 'woocommerce_order_status_cancelled', 'sms_notif_cancelled');
add_action( 'woocommerce_order_status_at-delivery', 'sms_notif_at_delivery');
add_action( 'woocommerce_order_status_at-reserved', 'sms_notif_at_reserved');
add_action( 'woocommerce_order_status_at-fitting', 'sms_notif_at_fitting');
add_action( 'woocommerce_order_status_shipping-progress', 'sms_notif_shipping_progress');
function sms_notif_order_status_updated($order_id, $status) {
global $woocommerce;
$order = wc_get_order( $order_id );
$billing_phone = (int)$order->get_billing_phone();
$shipping_phone = (int)get_post_meta( $order->get_id(), '_shipping_phone', true );
if (!$billing_phone && $shipping_phone) {
$billing_phone = $shipping_phone;
}
if ($billing_phone) {
switch ($status) {
case 'pending':
$message = "Bonjour, merci pour votre achat d'un montant de [ " . $order->get_total() . " TND ] auprès de ... Afficher la commande (#" . $order_id . ") : " . home_url() . "/mon-compte/voir-commande/" . $order_id . "/";
break;
case 'at_delivery':
$message = "Bonjour, votre commande (#" . $order_id . ") est chez ..., vous recevez votre colis dans les prochaine 48h. Bonne journée";
break;
case 'shipping_progress':
$message = "Bonjour, votre commande (#" . $order_id . ") est en cours de livraison, restez joignable. Bonne journée";
break;
case 'completed':
$message = "Félicitations vous avez reçu votre commande (#" . $order_id . "), vous trouverez les conditions de retour et échange avec votre bon de livraison. Merci d'avoir passé vos achats sur ... A très bien tôt";
break;
default:
return;
break;
}
if($status!="at_fitting"&&$status!="at_reserved")
$res = bulksms_send_message($billing_phone, $message);
// echo '<pre>'; var_dump($res);
// die();
}
}
function bulksms_send_message($phone_number, $message) {
$phone_number = sms_notif_filter_phone($phone_number);
if (!$phone_number) {
return;
}
$params = [
'key' => '...',
'fct' => 'sms',
'sender' => '...',
'mobile' => '216' . $phone_number,
'sms' => $message,
'date' => date('d/m/Y'),
'heure' => date('H:i'),
];
$params_string = '';
foreach($params as $key => $val) {
$params_string .= $key . '=' . urlencode($val) . '&';
}
$url = 'https://bulksms.bipsms.tn/Api/Api.aspx' . '?' . $params_string;
return Requests::get($url);
}
function sms_notif_filter_phone($phone_number) {
$phone_number = (int)$phone_number;
if (strpos($phone_number, '216') === 0) {
$phone_number = (int)substr($phone_number, 3, strlen($phone_number) - 3);
}
if (strpos($phone_number, '+216') === 0) {
$phone_number = (int)substr($phone_number, 4, strlen($phone_number) - 3);
}
if (strlen($phone_number) === 8) {
return $phone_number;
}
return null;
}
add_action( 'woocommerce_after_register_post_type', 'sms_notif_woocommerce_init', 10, 1 );
function sms_notif_woocommerce_init() {
if (isset($_GET['sms_notif_order_status_updated'])) {
sms_notif_order_status_updated(9469, 'completed');
}
}
function wc_register_post_statuses() {
register_post_status( 'wc-at-delivery', array(
'label' => _x( 'Chez Livreur', 'WooCommerce Order status', '...' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Chez livreur (%s)', 'Chez livreur (%s)', '...' )
) );
register_post_status( 'wc-at-reserved', array(
'label' => _x( 'Reservée', 'WooCommerce Order status', '...' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Reservée (%s)', 'Reservée (%s)', '...' )
) );
register_post_status( 'wc-at-fitting', array(
'label' => _x( 'Essayage', 'WooCommerce Order status', '...' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'Essayage (%s)', 'Essayage (%s)', '...' )
) );
register_post_status( 'wc-shipping-progress', array(
'label' => _x( 'En cours de livraison', 'WooCommerce Order status', '...' ),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
'show_in_admin_status_list' => true,
'label_count' => _n_noop( 'En cours de livraison (%s)', 'En cours de livraison (%s)', '...' )
) );
// add_filter( 'woocommerce_order_formatted_shipping_address', 'filter_woocommerce_order_formatted_shipping_address', 99, 3);
}
add_filter( 'init', 'wc_register_post_statuses');
function wc_add_order_statuses( $order_statuses ) {
$order_statuses['wc-at-delivery'] = _x( 'Chez Livreur', 'WooCommerce Order status', '...' );
$order_statuses['wc-at-reserved'] = _x( 'Reservée', 'WooCommerce Order status', '...' );
$order_statuses['wc-at-fitting'] = _x( 'Essayage', 'WooCommerce Order status', '...' );
$order_statuses['wc-shipping-progress'] = _x( 'En cours de livraison', 'WooCommerce Order status', '...' );
return $order_statuses;
}
add_filter( 'wc_order_statuses', 'wc_add_order_statuses' );
function filter_woocommerce_order_formatted_shipping_address_testtest( $array, $order ) {
$array = [
'x' => $order->get_billing_phone(),
];
return $array;
}
function filter_woocommerce_order_formatted_shipping_address( $array, $order ) {
if (isset($_GET['bewpi_action']) && $order) {
$array['company'] = $array['company'] . "\n" . $order->get_billing_phone();
}
return $array;
}
add_filter( 'woocommerce_order_formatted_shipping_address', 'filter_woocommerce_order_formatted_shipping_address', 10, 3 );
add_filter( 'woocommerce_order_formatted_billing_address', 'filter_woocommerce_order_formatted_shipping_address', 10, 3 );
其他一切都很好,只有我遇到的这个问题......如果有人需要其他细节,我很乐意将它们发布在这里。
解决方案
推荐阅读
- python - Tensorflow CNN 'tuple' object has no attribute 'initializer'
- ruby - 注入类级别函数的函数
- r - 一次使用一行不同的数据框:R
- service-worker - PWA:如果我的 Web 应用程序有一个没有清单文件的服务工作者会发生什么?
- python - 折叠/分组列表以聚合最大/最小值的 Pythonic 方式
- linux - ASP.NET Core 2 Web API - 502 Bad Gate Way(Centos 7) - NGINX
- html - Animation Flip HTML5 and CSS3 Doubts
- angular - Retrieve data from Firebase Ionic 3
- ajax - Sweetalert2 input validation with AJAX
- mysql - Spring boot - h2 和 mysql 的配置文件