WordPress multiple widget in single plugin

There is absolutely no problem with registering several widgets inside one file. Widgets are separate classes, and unlike other programming languages, PHP will have no problem with your declaring two classes inside one file. add_action( ‘widgets_init’, ‘src_load_widgets’ ); function src_load_widgets() { register_widget( ‘Widget_SRC’ ); register_widget( ‘Widget_Rank ‘ ); } class Widget_SRC extends WP_Widget { // … Read more

Woocommerce Change placement with wrapper

Okay I solved this but don’t know it is right way or wrong way. Hope you expert will give some better guideline. What I did just added two function into my add_action function and use those as a wrapper. // adding and re arranging placement function q2a_product_summary() { function wrapstart () { echo ‘<div class=”buy-box”>’; … Read more

Is there an action that is called when a post is restored from the trash?

There are multiple actions. Listed in order of appearance with their parameters: untrash_post – (int) $post_id // before restoring transition_post_status – (string) $new_status, ‘trash’, (object) $post trash_to_{$new_status} – (object) $post // useful to address a special trash to status action untrash_post_comments – (int) $post_id // before associated comments are untrashed untrashed_post_comments – (int) $post_id // … Read more

Is it possible to add an action to the currently running action?

You have to use a later (higher) priority. So use current_filter() to get the current hook and priority, add 1 to that priority, and register the next action: add_action( ‘init’, ‘func_1’ ); function func_1() { global $wp_filter; $hook = current_filter(); add_action( $hook, ‘func_2’, key( $wp_filter[ $hook ] ) + 1 ); } function func_2() { … Read more

How to add categories to products in woocommerce programatically? [closed]

I think the function you are looking for is called wp_insert_term() in WordPress core. Woocommerce uses WordPress-taxonomy called product_cat So if you want to add some categories for example phones: function wpse_insert_term() { wp_insert_term( ‘phones’, ‘product_cat’, // the taxonomy array( ‘description’=> ‘A yummy phone.’, ‘slug’ => ‘phone’, ) ); } add_action(‘init’, ‘wpse_insert_term’);

woocommerce hook publish product

I recommand you to use the transition_post_status. See example below : add_action(‘transition_post_status’, ‘wpse_110037_new_posts’, 10, 3); function wpse_110037_new_posts($new_status, $old_status, $post) { if( $old_status != ‘publish’ && $new_status == ‘publish’ && !empty($post->ID) && in_array( $post->post_type, array( ‘product’) ) ) { //add some cde here } } This hook is really handy. It allows you to target a … Read more