在WooCommerce中,我添加了一个定制产品类型来销售Google Meet网络研讨会.
- 首先,我已经添加了一个领域的管理产品页面,以放置谷歌会议链接(工程).
- 然后,当用户购买产品时,网络研讨会链接将显示在WooCommerce订单详细信息页面和感谢页面上(部分有效).
- 最后,一旦用户购买了产品,我将添加到购物车的按钮替换为一个自定义按钮,以"加入网络研讨会"链接到网络研讨会(不起作用).
我一直在努力修它,但是我没有修好它!
我还有以下几个问题:
- "谢谢"页面实际上正在崩溃.
- 购买产品后,添加到购物车按钮不会被"加入网络研讨会"文本所取代.
如有任何帮助,我们不胜感激.
到目前为止我的代码如下:
// Add Google Meet link field
function custom_add_google_meet_link_field() {
echo '<div class="options_group">';
woocommerce_wp_text_input(
array(
'id' => 'google_meet_link',
'label' => __('Google Meet Link', 'text-domain'),
'placeholder' => 'Enter Google Meet Link',
'desc_tip' => 'true',
'description' => __('Add your Google Meet link.', 'text-domain')
)
);
echo '</div>';
}
add_action('woocommerce_product_options_general_product_data', 'custom_add_google_meet_link_field');
// Save Google Meet link field data
function custom_save_google_meet_link_field_data($product_id) {
$google_meet_link = isset($_POST['google_meet_link']) ? sanitize_text_field($_POST['google_meet_link']) : '';
update_post_meta($product_id, 'google_meet_link', $google_meet_link);
}
add_action('woocommerce_process_product_meta', 'custom_save_google_meet_link_field_data');
// Display Google Meet link on order details and thank you page (clickable)
function custom_display_google_meet_link($order) {
$order_id = method_exists($order, 'get_id') ? $order->get_id() : $order->id;
$items = $order->get_items();
foreach ($items as $item) {
$product_id = $item['product_id'];
$google_meet_link = get_post_meta($product_id, 'google_meet_link', true);
if (!empty($google_meet_link)) {
echo '<h3>' . __('Google Meet Link:', 'text-domain') . '</h3>';
echo '<p><a href="' . esc_url($google_meet_link) . '">' . esc_html($google_meet_link) . '</a></p>';
}
}
}
add_action('woocommerce_order_details_after_order_table', 'custom_display_google_meet_link', 10, 1);
add_action('woocommerce_thankyou', 'custom_display_google_meet_link', 10, 1);
// Change "Add to Cart" button to "Join Webinar"
function custom_change_add_to_cart_button($button_text, $product) {
if ($product->get_type() === 'google_meet_webinar' && $product->is_purchasable()) {
$button_text = __('Join Webinar', 'text-domain');
}
return $button_text;
}
add_filter('woocommerce_product_single_add_to_cart_text', 'custom_change_add_to_cart_button', 10, 2);
add_filter('woocommerce_product_add_to_cart_text', 'custom_change_add_to_cart_button', 10, 2);