Remove specific product from shop in woocommerce [closed]

Add below hook to your theme function.php file add_action( ‘pre_get_posts’, ‘custom_pre_get_posts’ ); function custom_pre_get_posts( $q ) { if ( ! $q->is_main_query() ) return; if ( ! $q->is_post_type_archive() ) return; if ( ! is_admin() && is_shop() ) { $q->set( ‘tax_query’, array(array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘private-clients’, ‘charity’), // Don’t display products … Read more

Create template “author” with a plugin

You can riff off of how WooCommerce and other plugins are providing templates in their plugin, while allowing the theme to override them if they exist. Basically, you hook into the template_include function, which is where WordPress decides what template to load for a given query. Since you want to do something with the author.php … Read more

Auto delete WordPress users according to time

You can include this code by creating a new custom plugin which help you to stop this when you deactivate the plugin. wp_schedule_event(time(), ‘daily’, ‘my_dailyClearOut’); function my_clearOldUsers() { global $wpdb; $query = $wpdb->prepare(“SELECT ID FROM $wpdb->users WHERE datediff(now(), user_registered) > 7”); if ($oldUsers = $wpdb->get_results($query, ARRAY_N)) { foreach ($oldUsers as $user_id) { wp_delete_user($user_id[0]); } } … Read more

Plugin and theme script load order

For scritps and using the wp_register_script() function, you can define the dependeny of jQuery in the $deps argument, which is documented as: $deps: Array of the handles of all the registered scripts that this script depends on, that is, the scripts that must be loaded before this script. These scripts will automatically be enqueued when … Read more

Overwrite or Replace code in WP_Footer

Since you ruled out remove_action there is only one way you can do it. And you’ve guessed it: preg_repalce, substr mixture but with a little help and PHP DOM add_action(‘wp_footer’, ‘my_start_footer_ob’, 1); function my_start_footer_ob() { ob_start(“my_end_footer_ob_callback”); } add_action(‘wp_footer’, ‘my_end_footer_ob’, 1000); function my_end_footer_ob() { ob_end_flush(); } function my_end_footer_ob_callback($buffer) { // remove what you need from he … Read more

Getting user roles in plugin files

Figured my comment would actually make a better answer, so here we go. You can hook other methods within the plugin class onto admin_init (for the admin side) within the constructor, like so: class Plugin_Class { public function __construct() { add_action( ‘admin_init’, array( $this, ‘some_other_method’ ) ); } public function some_other_method() { // do something … Read more