我偶然看到这篇文章,想为由于update\\u post\\u meta而导致的多次重新提交寻找一个解决方案。看了这些帖子后,下面是我的解决方案wordpress get_post_meta check if multiple values set Prevent processing data multiple times in Woocommerce thankyou hook :
<?php
global $post;
$post = $order_id;
if ( isset( $_POST[\'submit\'] ) ){
echo \'Update nicht\';
} else
// Checking if this has already been done avoiding reload
if ( get_post_meta($order_id,"frontstrasse",true)!="" && get_post_meta($order_id,"fronthausnr",true)!="" {
return; // Exit if already processed
}
update_post_meta( $order_id, \'Strasse\', sanitize_text_field( $_POST[\'frontstrasse\'] ) );
update_post_meta( $order_id, \'Haus-Nr\', sanitize_text_field( $_POST[\'fronthausnr\'] ) );
}
$istrasse = get_post_meta($order->id, \'Strasse\', true );
$ihausnr = get_post_meta($order->id, \'Haus-Nr\', true );
?>
<form method="post" action="">
<label>Strasse</label><input type=\'text\' name=\'frontstrasse\' value=\'<?php echo $istrasse ?>\' />
<label>Haus-Nr</label><input type=\'text\' name=\'fronthausnr\' value=\'<?php echo $ihausnr ?>\' />
<input type=\'submit\' value=\'save\' name=\'frontsubmit\' />
</form>