Woocommerce比较两个元键并隐藏产品

时间:2018-12-12 09:01:43

标签: php wordpress woocommerce

我想在每种产品上设置元关键字_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();
}

0 个答案:

没有答案