我需要Woocommerce产品发布,更新和删除挂钩,如果有人知道请通知我。
我发现了这个钩子:
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
}
}但它只显示产品id,标题,发布状态etc....but我想要的产品价格,类别,标签,品牌和库存状态。
所以如果有人知道请重播我。
谢谢,凯坦。
发布于 2015-07-17 16:33:09
Woocommerce产品基本上都是wordpress的帖子。你可以使用wordpress钩子
add_action( 'before_delete_post', 'wpse_110037_new_posts' );
add_action( 'save_post', 'wpse_110037_new_posts' );
function wpse_110037_new_posts($post_id){
$WC_Product = wc_get_product( $post_id);
}wc_get_product()将返回WC_Product对象,您可以从中获取产品详细信息。
发布于 2017-03-01 04:32:34
我喜欢检查状态,如果不是草稿的话。您还可以使用第三个参数update来检查它是否是更新
add_action( 'save_post', array($this, 'wpse1511_create_or_update_product' ), 10, 3);
function wpse1511_create_or_update_product($post_id, $post, $update){
if ($post->post_status != 'publish' || $post->post_type != 'product') {
return;
}
if (!$product = wc_get_product( $post )) {
return;
}
// Make something with $product
// You can also check $update
}发布于 2021-11-12 18:33:38
此挂钩将在WC更新数据库中的产品后运行:
add_action('save_post_product', 'ns_sync_on_product_save', 10, 3);
function ns_sync_on_product_save( $post_id, $post, $update ) {
$product = wc_get_product( $post_id );
}https://stackoverflow.com/questions/31469415
复制相似问题