我想在每个产品上设置 meta-key _hide_if_stock,而不是将元键值_hide_if_stock_stock进行比较,并隐藏_stock <_hide_if_stock的产品。我通过此代码设置_hide_if_stock并且不知道如何将它与_stock进行比较:

function hide_if_stock(){
$args = array(
  'label' => 'Poniżej jakiej ilości produkt ma być ukrywany?', // Text in Label
  'placeholder' => '',
  'class' => '',
  'style' => '',
  'wrapper_class' => '',
  'value' => '', 
  'id' => 'hide_if_stock', 
  'name' => 'hide_if_stock', 
  'type' => '',
  'desc_tip' => '',
  'data_type' => '',
  'custom_attributes' => '', 
  'description' => ''
);
woocommerce_wp_text_input( $args );
}
add_action( 'woocommerce_process_product_meta', 'save_custom_field' );
function save_custom_field( $post_id ) {

  $custom_field_value = isset( $_POST['hide_if_stock'] ) ? $_POST['hide_if_stock'] : '';

  $product = wc_get_product( $post_id );
  $product->update_meta_data( 'hide_if_stock', $custom_field_value );
  $product->save();
}