![](/img/trans.png)
[英]Add product attribute or custom field in woocommerce admin order page
[英]How do you add custom field to woocommerce product attribute
我想在編輯屬性表單中包含一個簡單的。 (/wp-admin/edit.php?post_type=product&page=product_attributes&edit=55)
這可能嗎? 我在 SO 上找到的所有內容都與向產品或分類法添加字段有關,如果我沒記錯的話,產品屬性與分類法不同。
我想為我的“品牌”產品屬性添加一個自定義表單。
這是我嘗試過的(有和沒有 pa_):
add_action('pa_brand_edit_form_fields','msp_pa_brand_form_fields');
add_action('pa_brand_add_form_fields','msp_pa_brand_form_fields');
function msp_pa_brand_form_fields () {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="display"><?php _e('Display Type', ''); ?></label>
</th>
<td>
<select name="display_type">
<option value="select">Select</option>
<option value="variation_image">Variation Image w/ label</option>
</select>
</td>
</tr>
<?php
}
我只需要幫助讓一些 html 出現在這個編輯屏幕上。 我的總體計划是在每個屬性中添加這個 select 標簽,然后在變量中添加一段代碼。php 檢查屬性是如何顯示的。
任何幫助是極大的贊賞。
使用以下鈎子,您可以根據自己的意願在之前或之后添加一個字段
function action_woocommerce_before_edit_attribute_fields( ) {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="display"><?php _e('Display Type', ''); ?></label>
</th>
<td>
<select name="display_type">
<option value="select">Select</option>
<option value="variation_image">Variation Image w/ label</option>
</select>
</td>
</tr>
<?php
}
add_action( 'woocommerce_before_edit_attribute_fields', 'action_woocommerce_before_edit_attribute_fields', 10, 0 );
function action_woocommerce_after_edit_attribute_fields( ) {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="display"><?php _e('Display Type', ''); ?></label>
</th>
<td>
<select name="display_type">
<option value="select">Select</option>
<option value="variation_image">Variation Image w/ label</option>
</select>
</td>
</tr>
<?php
}
add_action( 'woocommerce_after_edit_attribute_fields', 'action_woocommerce_after_edit_attribute_fields', 10, 0 );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.