小编pie*_*rre的帖子

在购物车,结帐和查看订单中设置产品自定义字段和显示值

我已经通过function.php为我的产品页面创建了一个自定义保修字段.

add_action( 'woocommerce_product_options_general_product_data', 'test_custom_fields' );
function test_custom_fields() {
    // Print a custom text field
    woocommerce_wp_text_input( array(
        'id' => '_warranty',
        'label' => 'i.e. 15 years',
        'description' => '',
        'desc_tip' => 'true',
        'placeholder' => 'i.e. 15 years'
    ) );        
}

add_action( 'woocommerce_process_product_meta', 'test_save_custom_fields' );
function test_save_custom_fields( $post_id ) {
    if ( ! empty( $_POST['_warranty'] ) ) {
        update_post_meta( $post_id, '_warranty', esc_attr( $_POST['_warranty'] ) );
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在管理订单页面的自生成自定义字段中"复制"带有键和值的自定义字段,具体取决于购物车/订单中的产品(无插件).

因此,通过订单页面上的这个自定义字段,我终于可以使用WooCommerce PDF Invoice插件在我的pdf发票中显示"保修".

另一种解释:

  1. 作为管理员,我在"product1"页面填写_warranty值
  2. 当"product1"在订单中时,在管理订单视图中,我希望在product1页面中看到包含"_warranty + value"的自定义字段.
  3. 因此,作为管理员,我可以设置{{_warranty}}WooCommerce PDF Invoice插件显示"保修期:15年"

非常感谢您的帮助.

我刚刚测试了以下案例: …

php wordpress product orders woocommerce

6
推荐指数
1
解决办法
3292
查看次数

标签 统计

orders ×1

php ×1

product ×1

woocommerce ×1

wordpress ×1