php - 从 WordPress 中的函数获取值
问题描述
我对 WordPress 有点陌生,我有一个小问题。
我正在检查我的邮件是否已发送,并且我想将此信息保存在我制作的自定义表格中。我需要在另一个函数中检索此信息,然后将其保存在我的自定义表中。
这是我检查邮件是否发送的功能。
/*
* Send notification when stock is low
*/
function boilerplate_custom_low_stock_notification( $order ) {
foreach ( $order->get_items() as $item ) {
print_r($item);
if ( $item->is_type( 'line_item' ) && ( $product = $item->get_product() ) && $product->managing_stock() ) {
$new_stock = get_post_meta( $product->get_id(), '_stock', true );
$minimum_stock = get_post_meta( $product->get_id(), '_stock_minimum', true );
$stock = $product->get_stock_quantity();
$name = $product->get_name();
if ( $new_stock <= $minimum_stock ) {
//Send email to admin
$notification = wp_insert_post(
array(
'post_type' => 'shop_history',
'post_title' => 'The stock of '. $name . ' is running low.',
'post_content' => 'The stock is running low. There are only ' . $stock . " pieces left.",
'post_status' => 'publish',
) );
$mailResult = false;
$mailResult = wp_mail( get_option('admin_email'), 'Your stock is running low', 'The stock of ' . $name . ' is running low. You have ' . $stock . ' piece(s) left.' );
if( $mailResult == true){
$mail_send = "Mail was send";
}else{
$mail_send = "Something went wrong en there was no mail send";
}
//error_log( $mail_send );
return $notification;
}
}
}
}
add_action( 'woocommerce_reduce_order_stock', 'boilerplate_custom_low_stock_notification', 10, 3 );
在此功能中,我想保存信息。
/*
* Add values to column
*/
function woocommerce_shop_history_mail_column( $column, $post_id ) {
switch ( $column ) {
case 'mail' :
echo 'Is my mail send or not?';
break;
}
}
add_filter( 'manage_shop_history_posts_custom_column', 'woocommerce_shop_history_mail_column', 10, 2 );
解决方案
推荐阅读
- angularjs - 从 ngFor 循环中的元素覆盖“id” - AngularJS
- amazon-web-services - 表中缺少 DynamoDb 项目的数据
- flutter - Flutter Driver:一个接一个地运行标签或功能
- docker - 如何为在没有本地主机的 Windows 上的网络中运行的两个 docker 容器设置相同的 IP?
- php - MongoDB 全文搜索不适用于特定单词(不是停用词)
- android - 与 android 的双重配对请求。接收两个回调 sspRequestCallback
- python - 如何将这样格式化的字典列表转换为如下所示的数据框?(没有硬编码)
- html - Chatbox - 将聊天文本气泡与日期时间对齐
- python - 嵌入为 iframe 的 base64 编码 html 不会在 chrome 中显示,但会在 Firefox 中显示
- reactjs - 我有一个反应应用程序我通过道具从父组件发送api数据到子组件,它看到的值是未定义的