我目前没有一个WooCommerce来测试这个,所以它非常粗糙,准备就绪,甚至可能不起作用。。。但是,我认为逻辑是相当合理的。试一试:
// Store session value for table number
add_action(\'init\', \'store_table_number\');
function store_table_number() {
if( $_GET[\'dining\'] ) {
global $tableNo;
$tableNo = array( \'number\' => $_GET[\'dining\'] );
}
}
// Add Table Number field to checkout
add_filter( \'woocommerce_checkout_fields\' , \'table_number_checkout\' );
function table_number_checkout( $fields ) {
$fields[\'order\'][\'table_number\'] = array(
\'label\' => __(\'Table Number\', \'woocommerce\'),
\'placeholder\' => _x(\'Table\', \'placeholder\', \'woocommerce\'),
\'value\' => $GLOBALS[\'tableNo\'][\'number\'],
\'required\' => false,
\'class\' => array(\'form-row-wide\'),
\'clear\' => true
);
return $fields;
}
// Output table number in WP Admin panel
add_action( \'woocommerce_admin_order_data_after_shipping_address\', \'table_number_admin\', 10, 1 );
function table_number_admin($order){
echo \'<p><strong>\'.__(\'Table Number\').\':</strong> \' . get_post_meta( $order->get_id(), \'_table_number\', true ) . \'</p>\';
}
以上内容将添加到
functions.php 文件第一个函数启动会话并存储URL变量的值。第二个将表号字段添加到WooCommerce签出页面,引用自
here. 最后,第三个函数在WordPress管理员的订单屏幕中添加一个表号字段,这最终将允许您配置电子邮件输出。再次引用上述链接。