【发布时间】:2020-11-18 05:46:38
【问题描述】:
我正在创建一个活动票务 WordPress 主题,我正在使用 WooCommerce 和 Advanced custom fields (ACF) 插件。
我想更新一个名为事件的自定义帖子类型。与特定票的股票。这样我的客户就不需要查看 woo-commerce 产品页面,而只需打开一个“事件”
我尝试使用 update_post_meta 钩子,但这仅在管理员在管理工具中更新产品时有效。没有新订单。
function sync_product_stock( $meta_id, $post_id, $meta_key, $meta_value ) {
$postType = get_post_type( $post_id );
if ($postType == 'product' ) {
if ( $meta_key == '_stock' ) {
$product = wc_get_product( $post_id );
$eventId = $product->get_attribute( 'event_id' );
$productName = $product->get_name();
if ($productName.include('Early Bird')) {
update_field( 'event_early_bird_group_event_early_bird_amount_of_tickets', $meta_value, $eventId );
} else if ($productName.include('Regular')) {
update_field( 'event_regular_group_event_regular_amount_of_tickets', $meta_value, $eventId );
} else if ($productName.include('Member')) {
// nothing needs to be updated
}
}
}
}
add_action( 'updated_post_meta', 'sync_product_stock', 10, 4);
如何在_stock 字段更新时收到通知? (我不想自己处理库存
【问题讨论】:
标签: php wordpress woocommerce custom-post-type hook-woocommerce