将自定义 "Booking" 按钮添加到 WooCommerce 产品单页
Add custom "Booking" button to WooCommerce Product single pages
遇到此问题,如有任何帮助,我们将不胜感激!
我希望我的每个 woocommerce 单一产品页面都有一个按钮 "Book Now",该按钮链接到我在 WordPress 上创建的标题为 "Booking Appointments".
的页面
"Booking Appointments" 页面包含我安装的 "Easy Appointment" 插件表格(客户将填写),我还希望它自动将产品的 SKU 或值填充到其中一个表单输入(来自上一页),这样我就不必每次都输入它。
网上试了各种方法都不行
在content-single-product.php
的最后你可以添加
<a class="button-link" href="<?php
get_page_by_path(booking-appointments);
?>">Booking Appointments</a>
然后使用 .button-link 将 link 设置为按钮样式。
已更新
这将在单个产品页面中添加一个 "Book Now" 按钮 链接到您的 "Booking Appointments" 页面 通过 URL 产品 ID,产品 sku…
所以代码将是:
// Add a custom button in Single product pages
add_action( 'woocommerce_single_product_summary', 'replacing_template_single_add_to_cart', 31, 0 );
function replacing_template_single_add_to_cart() {
global $product;
$product_id = $product->get_id();
$sku = $product->get_sku();
// Set below the page ID, your button text and link parameters to pass in url
$page_id = 124;
$button_text = __('Book Now', 'woocommerce');
$link = get_permalink( $page_id ) . '?id=' . $product_id . '&sku=' . $sku;
// Output your custom text
echo '<a href="'.$link.'" class="book-now button">'.$button_text.'</a>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
In your your "Booking Appointments" page form you will be able to get the values from the URL with $_GET
to populate necessary fields with an additional scripts in which you will use:
$product_id = $_GET['id'];
$sku = $_GET['sku'];
在 WooCommerce 3+ 中测试和工作。
遇到此问题,如有任何帮助,我们将不胜感激!
我希望我的每个 woocommerce 单一产品页面都有一个按钮 "Book Now",该按钮链接到我在 WordPress 上创建的标题为 "Booking Appointments".
的页面"Booking Appointments" 页面包含我安装的 "Easy Appointment" 插件表格(客户将填写),我还希望它自动将产品的 SKU 或值填充到其中一个表单输入(来自上一页),这样我就不必每次都输入它。
网上试了各种方法都不行
在content-single-product.php
的最后你可以添加
<a class="button-link" href="<?php
get_page_by_path(booking-appointments);
?>">Booking Appointments</a>
然后使用 .button-link 将 link 设置为按钮样式。
已更新
这将在单个产品页面中添加一个 "Book Now" 按钮 链接到您的 "Booking Appointments" 页面 通过 URL 产品 ID,产品 sku…
所以代码将是:
// Add a custom button in Single product pages
add_action( 'woocommerce_single_product_summary', 'replacing_template_single_add_to_cart', 31, 0 );
function replacing_template_single_add_to_cart() {
global $product;
$product_id = $product->get_id();
$sku = $product->get_sku();
// Set below the page ID, your button text and link parameters to pass in url
$page_id = 124;
$button_text = __('Book Now', 'woocommerce');
$link = get_permalink( $page_id ) . '?id=' . $product_id . '&sku=' . $sku;
// Output your custom text
echo '<a href="'.$link.'" class="book-now button">'.$button_text.'</a>';
}
代码进入您的活动子主题(或主题)的 function.php 文件或任何插件文件。
In your your "Booking Appointments" page form you will be able to get the values from the URL with
$_GET
to populate necessary fields with an additional scripts in which you will use:$product_id = $_GET['id']; $sku = $_GET['sku'];
在 WooCommerce 3+ 中测试和工作。