How can I add an extra WooCommerce hook

You can create a hook by calling do_action, then referring to the hook in your functions.php with add_action. For example, in the theme, where you want the action to occur: do_action(‘woocommerce_before_single_product_intro’); Then in functions.php add_action(‘woocommerce_before_single_product_intro’,’your_function’,[…]); For the sake of maintainability, I’d choose a naming convention that doesn’t confuse your hooks with WooCommerce’s.

How to handel multiple checkbox field in the admin settings page with Settings API

add_action( ‘admin_init’, ‘register_page_options’ ); function register_page_options() { if (false == get_option(‘aicp_settings_options’)) { add_option(‘aicp_settings_options’); } // Add Section for option fields add_settings_section( ‘aicp_section’, __( ‘….text here….’, ‘aicp’ ), ‘display_section’, ‘aicp_settings’ ); // id, title, display cb, page // Add Field for selecting countries for which you wanna ban ads add_settings_field( ‘aicp_country_list’, __( ‘Select the countries’, ‘aicp’ … Read more

Change number of posts to show on Archive page (custom post type)

Just make sure you’re not in the admin when changing the query: function num_posts_archive_project_ie($query) { if (!is_admin() && $query->is_archive(‘projects-ie’) && $query->is_main_query()) { $query->set(‘posts_per_page’, 6); } return $query; } is_admin() does return true only if you’re in the backend (it does not, however, verify that the current user is an admin user, despite the name, don’t … Read more

Find callback function for custom taxonomy metabox

The callback you need for non-hierarchical taxonomies is post_tags_meta_box. The callback you need for hierarchical taxonomies is post_categories_meta_box. For your example, the code would be: /* Remove movies metabox from sidepanel */ function hide_metabox(){ remove_meta_box( ‘tagsdiv-movies’, ‘your-post-type’ , ‘side’ ); } add_action( ‘admin_menu’ , ‘hide_metabox’ ); /* Add back movies metabox, but in post area … Read more

WordPress plugin how to run function when button is clicked

Create form or link with action=”my_media_update” <form action=”<?php echo admin_url(‘admin-post.php’); ?>” method=”post”> <input type=”hidden” name=”action” value=”my_media_update”> <input type=”submit” value=”Update Media Titles and ALT Text”> </form> Add this function and hook in your plugin file: public function kh_update_media_seo() { //update media files title and alt tags here // // at the end redirect to target page … Read more

Influence of WordPress functions on site speed

Functions and includes (itself) don’t affect the site performance much. But… The code inside a function can affect site speed. It all depends what exactly that function does. For example function esc_attr won’t affect site speed, because its code is simple and will run fast. On the other hand, functions like get_posts can take a … Read more