I have a simple question, I am working on the list order screen of woocommerce and want to add some buttons that via ajax will update some data to the database using update_post_meta. The issue is that these buttons are pressed with a frequency more or less 10 times/minute. … [Read more...] about update_post_meta performance in a loop woocommerce
Update_post_meta order
get_post_meta and add_post_meta not working
$ggowlccpy_transaction_details_capture = array( 'merchant_ref' => $ggowlccpy_order_id, 'transaction_id' => $ggowlccpy_response['transaction_id'], 'transaction_tag' => $ggowlccpy_response['transaction_tag'], 'method' => $ggowlccpy_response['method'], 'amount' => $ggowlccpy_response['amount'], 'currency_code' => $ggowlccpy_response['currency'], 'positionofsave' => 'captured', ); update_post_meta($post->ID, '_ggowlccpy_trasaction_capture', $ggowlccpy_transaction_details_capture); add_post_meta( $post->ID, '_ggowlccpy_refund_details_get', base64_encode(serialize($ggowlccpy_transaction_details_capture)) ); $data = get_post_meta( $ggowlccpy_order_id, $key = '_ggowlccpy_refund_details_get', $single = false ); $tb_meta_unserialized = unserialize(base64_decode($data)); error_log(var_export($tb_meta_unserialized, 1)); echo $tb_meta_unserialized; … [Read more...] about get_post_meta and add_post_meta not working
Woocommerce: Reallocate orders to a new user within a date range
function reassign_orders( ){ if(!is_admin()) return; else { $new_customer_id = 286; // Iterating with a loop through a range of numbers for( $order_id = 22680; $order_id <= 22680; $order_id++ ){ // Getting the postmeta customer ID for 'order' post-type $customer_id = get_post_meta( $order_id, '_customer_user', true ); // If it's an existing order and doesn't already have this user ID // It update the customer ID if( !empty($customer_id) && $new_customer_id != $customer_id ) update_post_meta( $order_id, '_customer_user', $new_customer_id ); } } } reassign_orders(); … [Read more...] about Woocommerce: Reallocate orders to a new user within a date range
How to perform multiple metadata posting for different orders in Woocommerce?
My friend suggested to remove the ajax call from the checkboxes and make some array that saves these values to post them all at the same time. What would be the most efficient method to do this? If I use the previous 3 lines of code in a loop wouldn't they crash the database? … [Read more...] about How to perform multiple metadata posting for different orders in Woocommerce?
Hidden Form Custom Post Meta Field for Storing Post_id using PHP and save_post hook
add_action('save_post', set_post_meta_field_value, 10,3); function set_post_meta_field_value( $post_id, $post, $update ) { // only want to set if new post if ( $update ) { return; } // only set for post_type = puppy if ( 'post' !== $post->get_post_type() ) { return; } // set listing-post-id meta field to the $post_id $post_id = get_post(); add_post_meta($post_id, 'listing-post-id', $post_id); } Any ideas on what I'm missing would be greatly appreciated. … [Read more...] about Hidden Form Custom Post Meta Field for Storing Post_id using PHP and save_post hook