与供应商(WC供应商)一起开发WooCommerce网上商店.
我需要显示我在供应商资料中创建的自定义字段.它应显示在项目和供应商名称下order-details.php.
如何按卖家/供应商ID显示个人资料字段?
有人可以帮帮我吗?
这是我将要撒谎的屏幕截图:
配置自定义字段
向用户个人资料页面添加自定义字段
add_action( 'show_user_profile', 'wp_added_user_profile_fields' );
function wp_added_user_profile_fields( $user ) {
?>
<table class="form-table">
<tr>
<th><label for="billing_enumber"><?php _e( "eNumber", 'woocommerce' ); ?></label></th>
<td>
<input type="text"
name="billing_enumber"
id="billing_enumber"
class="regular-text"
value="<?php echo esc_attr( get_the_author_meta( 'billing_enumber', $user->ID ) ); ?>"/>
<span class="description"><?php _e( 'Please enter your eNumber.', 'woocommerce' ); ?></span>
</td>
</tr>
</table>
<?php
}
Run Code Online (Sandbox Code Playgroud)
将更新功能添加到用户配置文件的自定义字段
add_action( 'edit_user_profile', 'wp_added_user_profile_fields' );
function wp_save_added_user_profile_fields( $user_id ) {
if ( current_user_can( 'edit_user', $user_id ) ) {
update_user_meta( $user_id, 'billing_enumber', …Run Code Online (Sandbox Code Playgroud) 是否可以在订单内的产品上添加元数据?
在这种情况下,将有一个元数据,但每个产品(按顺序)将具有不同的值.例:
Order 1:
* Product 1
Sample Meta: Meta1
* Product 2
Sample Meta: Meta2
Run Code Online (Sandbox Code Playgroud)
谢谢.
Update1:
我现在停留在如何从woocommerce_add_cart_item_data过滤器中获取值.我能够从那里成功添加元数据.
我需要抓住这些值才能在此woocommerce_add_order_item_meta动作钩子中使用.
这是我成功将元数据添加到过滤器的方式:
function add_cart_item_data( $cart_item_data, $product_id ) {
$cart_item_data[ "meta1" ] = $_POST["meta1"];
$cart_item_data[ "meta2" ] = $_POST["meta2"];
return $cart_item_data;
}
add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 99, 2 );
Run Code Online (Sandbox Code Playgroud)