0
我想爲每個商店自定義帖子類型在WooCommerce產品中創建一個存儲級別字段。 我已經創建了商店自定義帖子類型並向其添加了3個商店。每次有人添加商店時,我都想自動添加「商店的庫存水平」字段,以便我可以在商店級檢查庫存。wordpress爲每個自定義類型添加字段
我試圖把自定義字段放在庫存數量下的Products-> Inventory->右邊。
我已經試過這樣:
$post_type = 'store';
$tax = 'show-topic';
$inv_arg_terms = get_terms(array('orderby' => 'id', 'order' => 'ASC'));
if ($inv_arg_terms) {
$args = array(
'post_type' => $post_type,
'post_status' => 'publish',
'posts_per_page' => - 1,
'orderby' => 'title',
'order' => 'ASC'
); // END $args
$my_query = null;
$my_query = new WP_Query($args);
if ($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post();
add_action('woocommerce_product_options_inventory_product_data', 'wc_inventory_stock_product_field');
function wc_inventory_stock_product_field() {
woocommerce_wp_text_input(array('id' => 'stock_level_' . the_title(), 'class' => 'short wc_input_stock', 'label' => __('Stock Level at ' . the_title(), 'woocommerce') . ' (' . get_woocommerce_currency_symbol() . ')'));
}
add_action('save_post', 'wc_cost_save_product');
function wc_cost_save_product($product_id) {
// stop the quick edit interferring as this will stop it saving properly, when a user uses quick edit feature
if (wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce'))
return;
// If this is a auto save do nothing, we only save when update button is clicked
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return;
if (isset($_POST['stock_level_' . the_title()])) {
if (is_numeric($_POST['stock_level_' . the_title()]))
update_post_meta($product_id, 'stock_level_' . the_title(), $_POST['cost_price']);
} else delete_post_meta($product_id, 'stock_level_' . the_title());
}
endwhile;
} // END if have_posts loop
wp_reset_query();
} // END if $inv_arg_terms
,我得到這個:
Fatal error: Call to undefined function get_userdata() in .../wp-includes/query.php on line 4758
是什麼,我想可能嗎?我該如何解決它?
謝謝,感謝我能得到的每一個幫助。