我正在向我的结帐表单添加一些自定义字段woocommerce形式,文本fiels在订单摘要页面(对于User / Cliecnt)显示精确值,对管理员显示相同。但如果我使用“Selcet”类型,则不会显示实际值
这是代码
SAVE THE EXTRA DATA ON CHECKOUT
// save the extra field when checkout is processed
function kia_save_extra_checkout_fields( $order_id, $posted ){
// don't forget appropriate sanitization if you are using a different field type
if( isset( $posted['some_field'] ) ) {
update_post_meta( $order_id, '_some_field', sanitize_text_field( $posted['some_field'] ) );
}
if( isset( $posted['another_field'] ) && in_array( $posted['another_field'], array( 'a', 'b', 'c' ) ) ) {
update_post_meta( $order_id, '_another_field', $posted['another_field'] );
}
}
add_action( 'woocommerce_checkout_update_order_meta', 'kia_save_extra_checkout_fields', 10, 2 );
DISPLAY THE EXTRA DATA TO USERS
// display the extra data on order recieved page and my-account order review
function kia_display_order_data( $order_id ){ ?>
<h2><?php _e( 'Additional Info' ); ?></h2>
<table class="shop_table shop_table_responsive additional_info">
<tbody>
<tr>
<th><?php _e( 'Some Field:' ); ?></th>
<td><?php echo get_post_meta( $order_id, '_some_field', true ); ?></td>
</tr>
<tr>
<th><?php _e( 'Another Field:' ); ?></th>
<td><?php echo get_post_meta( $order_id, '_another_field', true ); ?></td>
</tr>
</tbody>
</table>
<?php }
add_action( 'woocommerce_thankyou', 'kia_display_order_data', 20 );
add_action( 'woocommerce_view_order', 'kia_display_order_data', 20 );
$ mvn package
$ cd target
$ java -cp ./desktop-2.3.3.jar:.:test-classes/ com.github.axet.desktop.DesktopTest
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/jna/Platform
at com.github.axet.desktop.Desktop.getDesktopFolders(Desktop.java:53)
at com.github.axet.desktop.Desktop.getHomeFolder(Desktop.java:32)
at com.github.axet.desktop.DesktopTest.main(DesktopTest.java:10)
Caused by: java.lang.ClassNotFoundException: com.sun.jna.Platform
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
因此,不是“Apple”(在我的情况下是性别),它在结帐后的摘要页面显示“a”,这是截图 Screenshot for the reference
以下是教程链接:http://www.kathyisawesome.com/woocommerce-customize-checkout-fields/和Woocommerce版本为2.5.5
请帮助, 谢谢。
答案 0 :(得分:0)
尝试替换
'options' => array(
'a' => __( 'apple' ),
'b' => __( 'bacon' ),
'c' => __( 'chocolate' )
),
与
'options' => array(
'' => _('Please Select An Option...', 'woocommerce'),
'a' => _('Apple', 'woocommerce' ),
'b' => _('Bacon', 'woocommerce' ),
'c' => _('Chocolate', 'woocommerce' )
),
或
'options' => array( 'a' => 'Apple',
'b' => 'Bacon',
'c' => 'Chocolate' ),
答案 1 :(得分:0)