Conditional action hooks

During page request, WordPress actions are triggered in a sequence, therefore you have to register them in time. In your case, wp_head comes after wp_enqueue_scripts, so as a solution, i would all remove them from the wp_head and register them all in a condition, outside of any other action: if ( isset( $_COOKIE[‘user_opt’] ) ) … Read more

Can I differentiate between “Delete Post Permanently” and “Empty Trash” and do something for each accordingly?

So as leymannx pointed out in his comment, the “delete_post” hook actually handles both scenarios I was looking for, as it seems to know to run a “for each post deleted, do x” when “Empty Trash” is clicked and will also “do x” when “Delete Post Permanently” is clicked! My final code ended up looking … Read more

Customize WooCommerce orders displayed shipping

There are mainly 2 filters to be used: 1) the filter woocommerce_order_shipping_to_display located in get_shipping_to_display() method, used by get_order_item_totals() method to display the shipping in order total rows: add_filter( ‘woocommerce_order_shipping_to_display’, ‘customize_order_shipping_to_display’, 10, 3 ); function customize_order_shipping_to_display( $shipping, $order, $tax_display ){ // Your code to filter displayed shipping return $shipping; } 2) Or filter woocommerce_get_order_item_totals located … Read more

admin_notices not working in post editor

So it looks like there is some page redirecting going on in the post updating process, hence why I can’t even access a $GLOBALS variable. The only alternative I found to use was to use a session variable. Something like: add_filter( ‘pre_insert_term’, ‘pre_insert_term_action’, 10, 2 ); add_action( ‘admin_notices’, ‘show_example_error’ ); function pre_insert_term_action( $term, $taxonomy ) … Read more

hooks & filters and variables

If you want to return the data, the best solution is to use apply_filters() and instruct the callback to always return: $output = apply_filters( ‘hook_data_handle_’.$args[‘UID’], $args, $options ); if ( $args[‘echo’] ) echo $output; else return $output; A less elegant solution would be to use output buffering.

How to get post ID in post_updated action hook?

You should be able to get the ID of the post through the $_POST variable. EDIT: Maybe you should try doing this on the save_post action, like so, but save_post sometimes runs on other instances (ie. Autosave Drafts), so you’ll want to do some more verifying. save_post will also return the ID as one of … Read more