how to add custom functionality after woocommerce place order button

You can use woocommerce_after_checkout_validation for custom validation. Following snippet might be helpful for you. //Action to validate add_action(‘woocommerce_after_checkout_validation’, ‘after_checkout_otp_validation’); //The function function after_checkout_otp_validation( $posted ) { // you can use wc_add_notice with a second parameter as “error” to stop the order from being placed if (error) { wc_add_notice( __( “Incorrect OTP!”, ‘text-domain’ ), ‘error’ ); … Read more

How to load a template-part based on a url wildcard?

I ended up with this solution in functions.php, thanks to the offical WordPress documentation at: https://codex.wordpress.org/Rewrite_API/add_rewrite_rule First added a custom rewrite rule like so: function custom_rewrite_rule() { add_rewrite_rule( ‘^agenda/([^/]*)/([^/]*)/?’, ‘index.php?page_id=10&agenda_id=$matches[1]&agenda_name=$matches[2]’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite_rule’, 10, 0 ); Then this needed to be added: function prefix_register_query_var( $vars ) { $vars[] = ‘agenda_id’; $vars[] = … Read more

Modifying meta tags after doing ajax call in plugin

It took me a while of tinkering with the hooks, but in the end, I fixed it by loading the post earlier. Instead of loop_start: $this->loader->add_action(‘loop_start’, $plugin_public, ‘mp_display_post’); I used get_header: $this->loader->add_action(‘get_header’, $plugin_public, ‘mp_display_post’); This worked properly because now the post information is loaded before wp_head gets called, and therefore I can use the loaded … Read more

Add function to every post?

One way to do that is to have the custom dropdown function return the custom html. Then you can call it inside your add_dropdown_to_posts and put the returned content into a helper variable. After that just prepend the custom html to the $content variable that the the_content filter provides. Like this, function my_custom_dropdown_html() { return … Read more

Handling Body class based on Template

I’m not sure if I understand your question correctly, but… If you want to set body classes based on current page, then you can use this code function my_body_class( $classes ) { if ( is_home() ) { $classes[] = ‘wbody’; } else { $classes[] = ‘gbody’; } return $classes; } add_filter( ‘body_class’, ‘my_body_class’ ); Of … Read more

Inserting a functions output after the content

Your shares_content function directly outputs content, which won’t work if you’re trying to assign the results to a variable or use it in a return statement within another function. You can change it to return the string: function shares_content() { $content = “<div class=”social-shares-container”><a href=”https://www.facebook.com/sharer/sharer.php?u=%s”>Share on Facebook</a></div>”; return sprintf( $content, get_permalink() ); } It’s also … Read more