0

我正在使用 woocommerce 预订插件,我正在为已经预订时间段的客户寻找一种解决方案,以便能够为他们的预订增加更多时间。从理论上讲,如果他们可以编辑他们的预订并支付差价,那就太好了,但据我所知,这将需要大量的自定义代码,而我无法做到这一点。因此,作为替代解决方案,也许我可以在客户的订单详细信息页面上创建一个独特的按钮,在/my-account/booking-details/OrderID/那里他们可以根据该订单的产品转到特定产品。

我在 /order-details.php 文件上创建了一个名为 woocommerce_extra_time_button 的自定义钩子,并将以下代码添加到我的主题的 function.php 文件中,但我无法像我想的那样提取产品 URL。

add_action( 'woocommerce_extra_time_button', 'booking_extratime_button', 10, 3 );
function booking_extratime_button( $item_id, $item ){
    $url = get_permalink( $item['product_id'] ) ;

    return '<a href="'. $url .'">'. $item_id .'</a>'; 
}
4

1 回答 1

0

您可以从当前用户的订单中找到产品详细信息,并在自定义挂钩中使用。例如 :

$order = wc_get_order( $order_id );
$items = $order->get_items()
foreach ( $items as $item ) {
    $product_name = $item->get_name();
    $product_id = $item->get_product_id();
    $product_variation_id = $item->get_variation_id();
}
于 2019-07-10T05:14:04.987 回答