How to get a value from another function

I am a bit new to WordPress and i have a small problem.

I’m checking if my mail was send or not and i want to save this information in a custom table that i made. I need to retrieve this information in a different function where I then save this in my custom table.

This is the function where i check if the mail is send or not.

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

In this function i want to save the information.

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

The information in the $mail_send is what I need in my woocommerce_shop_history_mail_column function to echo it in my custom column.

Read more here:: How to get a value from another function

Leave a Reply

Your email address will not be published. Required fields are marked *