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