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