How do I fix Undefined variable using $_POST in function?

Your check is incorrect: right now, it tries to access $_POST[‘rating’], which might not be set, and then checks whether that value is empty. Furthermore, you should scope your if statement with brackets, because right now, your code will try and update the average rating even if no new rating is provided. Try: function save_comment_meta_rating( … Read more

Custom field in PHP file

Assuming your $hasp_expire_date = get_post_meta( $post_id, ‘hasp_expire_date’, true ); is giving you the correct value you need, you are storing your that in the $hasp_expire_date variable. So edit that second line to: $num_comments = get_comments_number( $block_data[‘id’] ); // Pull in the value you need $hasp_expire_date = get_post_meta( $post_id, ‘hasp_expire_date’, true ); // You are going … Read more

WooCommerce – template_redirect if is_checkout AND order has been paid?

I figured it out. woocommerce_payment_succesful_result guided me in the right direction, although it wasn’t the final answer. function is_wc_endpoint_url() is really useful here, it checks where woocommerce is about to redirect next. // redirect empty checkouts and completed orders. add_action( ‘template_redirect’, ‘myfunction’ ); function myfunction() { if( is_wc_endpoint_url( ‘order-received’ ) && isset( $_GET[‘key’] ) ) … Read more