WordPress/WooCommerce - 自定义类别批量编辑的钩子是什么?

时间:2021-01-22 11:33:42

标签: php wordpress woocommerce

我在 WooCommerce 产品类别编辑中添加了批量操作。我只想知道当我点击 Apply 对选定类别执行某些操作时的钩子是什么。 (具体来说,我想通过更新 wp_termmeta 表并将 example 值设置为 10 来更新所有选定的类别)我唯一想要的是名称单击 Apply 中的 /wp-admin/edit-tags.php?taxonomy=product_cat&post_type=product 按钮时的钩子。

Bulk Action

1 个答案:

答案 0 :(得分:0)

只需复制并粘贴到您的functions.php 中即可。享受

// Note: change all occurrences of "custom_field" with the key of your custom field add_action( 'woocommerce_product_bulk_edit_start', 'bbloomer_custom_field_bulk_edit_input' ); function bbloomer_custom_field_bulk_edit_input() { ?> <div class="inline-edit-group"> <label class="alignleft"> <span class="title"><?php _e( 'Custom Field', 'woocommerce' ); ?></span> <span class="input-text-wrap"> <input type="text" name="custom_field" class="text" value=""> </span> </label> </div> <?php } add_action( 'woocommerce_product_bulk_edit_save', 'bbloomer_custom_field_bulk_edit_save' ); function bbloomer_custom_field_bulk_edit_save( $product ) { $post_id = $product->get_id(); if ( isset( $_REQUEST['custom_field'] ) ) { $custom_field = $_REQUEST['custom_field']; update_post_meta( $post_id, 'custom_field', wc_clean( $custom_field ) ); } }