admin管理员组文章数量:1126097
I am trying to run a function every time a new product is added on woocommerce, for so I am using woocommerce_new_product action. For this I add a new action
function uniqueNameFunction($id) {
wp_die("event worked");
}
add_action('woocommerce_new_product', 'uniqueNameFunction', 10, 1);
I suspect maybe I do not register it correctly in my plugin, so to make sure I do it right I regenerated a plugin using this tool and add it along with other actions already in the template.
In order to test it I just add a new product using admin UI.
This does not fire, and I have no idea why and how to debug it. Would be nice if someone gives me some ideas. Thanks!
I am trying to run a function every time a new product is added on woocommerce, for so I am using woocommerce_new_product action. For this I add a new action
function uniqueNameFunction($id) {
wp_die("event worked");
}
add_action('woocommerce_new_product', 'uniqueNameFunction', 10, 1);
I suspect maybe I do not register it correctly in my plugin, so to make sure I do it right I regenerated a plugin using this tool and add it along with other actions already in the template.
In order to test it I just add a new product using admin UI.
This does not fire, and I have no idea why and how to debug it. Would be nice if someone gives me some ideas. Thanks!
Share Improve this question edited Oct 1, 2018 at 10:36 Marek asked Oct 1, 2018 at 10:31 MarekMarek 1135 bronze badges2 Answers
Reset to default 3Try like
function add_this_to_new_products( $new_status, $old_status, $post ) {
global $post;
if ( $post->post_type !== 'product' ) return;
if ( 'publish' !== $new_status or 'publish' === $old_status ) return;
add_post_meta( $post->ID, 'total_amount', '0', true ); // This is the action to take
}
add_action( 'transition_post_status', 'add_this_to_new_products', 10, 3 );
It doesn't fire because there's a issue with this hook.
As stated by the support team on this -> https://github.com/woocommerce/woocommerce/issues/23610
Looks like it does fire when you puts the product on draft, but most users (like you and me) don't see this way. Should fires every time a product is created.
本文标签: woocommerce offtopicwoocommercenewproduct action doesn39t fire
版权声明:本文标题:woocommerce offtopic - woocommerce_new_product action doesn't fire 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736682316a1947482.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论