calculate values from a field and insert them into custom fields when publishing or updating post

You can achieve this using the save_post hook, this is a hook that fires once a post has been saved. Below is an example addressing what you want to achieve: function wpse253778_calculate_values( $post_id, $post ) { if ( ‘post’ !== $post->post_type ) return; $field = get_post_meta( $post_id, ‘FIELD_NAME’, true ); //get field value $new_field_value=””;//calculate new … Read more

Change user role if it’s orders count more than

Thank you for all people that help me to find an answer (0 helpers)! I found a solution on my own. function wpa_120656_convert_paying_customer( $order_id ) { $order = new WC_Order( $order_id ); $user_id = $order->user_id; $customer_orders = get_posts( array( ‘numberposts’ => -1, ‘meta_key’ => ‘_customer_user’, ‘meta_value’ => $user_id, ‘post_type’ => ‘shop_order’, ) ); if ( … Read more

WordPress sending data with add_action

This is untested but you should be able to hook into ‘wcvendors_approve_vendor’ action. It is also passing the $wp_user_object to you which you could get the user id from…OR $_GET is a global, so you can still access $_GET[‘user_id’] if you wanted. The ’10’ in the add_action is the priority and the ‘1’ tells it … Read more

Can add_image_size be added earlier

You can set the priority to 999 to make sure if you are going that way: add_action( ‘after_setup_theme’, ‘_my_action_add_image_sizes’, 999 ); but if you really want to make sure of that order, try making a custom action, here a small example: /** * Execute the action with do_action. */ function read_theme_options() { //all the logic … Read more

Display custom debug info inside page and not before head

Don’t print any debug info into the page directly. WordPress offers a wp-content/debug.log file which you can use. Enable debug and debug_log in your wp-config.php define( ‘WP_DEBUG’, true ); // turn debug mode on define( ‘WP_DEBUG_DISPLAY’, false ); // do not display errors define( ‘WP_DEBUG_LOG’, true ); // save errors to wp-content/debug.log define( ‘SAVEQUERIES’, true … Read more

remove_action() hook not working

Actions (and filters) can be removed only after they had been set, therefor you will have to figure out when in the execution path the woocommerce_template_single_excerpt is being added, and remove it only after that.

add extra parameter in default hook in wordpress

You don’t really need to add this parameter, you can use global $post; function bp_add_visibility_to_activity( $content, $user_id, $activity_id ) { global $post; $post_id = $post->ID; // do stuff } add_action( ‘bp_activity_posted_update’, ‘bp_add_visibility_to_activity’, 10, 3 ); Note that $post->ID will return null if your are not in a post or page, so you maybe need to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)