我已经通过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发票中显示"保修".
另一种解释:
{{_warranty}}WooCommerce PDF Invoice插件显示"保修期:15年"非常感谢您的帮助.
我刚刚测试了以下案例: …