实例
我尝试了这段代码来创建自定义选项卡和输入,现在我正在寻找如何在订单详细信息页面上保存和显示输入文本。我想在新的自定义选项卡中添加文本,并在订单详情页中显示该文本
add_filter('woocommerce_product_data_tabs', 'custom_tab'); function custom_tab($tabs) { $tabs['ppwp_woo'] = array( 'label' => 'Custom Link', 'target' => 'ppwp_woo_options', 'priority' => 65, ); return $tabs; } add_action( 'woocommerce_product_data_panels' ,'custom_tab_content' ); function custom_tab_content() { global $woocommerce, $post; ?> <div id="ppwp_woo_options" class="panel woocommerce_options_panel"> <?php woocommerce_wp_text_input( array( 'id' => '_custom_link', 'label' => __( 'link', 'woocommerce' ), 'desc_tip' => 'true', 'description' => __( 'Insert any text that you want to include in the order product details.', 'woocommerce' ), ) ); ?> </div> <?php } add_action( 'woocommerce_process_product_meta', 'save_options' ); function save_options($product_id) { $keys = array( '_custom_link', ); foreach ($keys as $key) { if (isset($_POST[$key])) { update_post_meta($product_id, $key, $_POST[$key]); } } }