【问题标题】:Conditional WooCommerce Confirmation/Order Received Page based on Product or Category?基于产品或类别的有条件的 WooCommerce 确认/订单接收页面?
【发布时间】:2014-01-30 15:44:56
【问题描述】:

我在 WooCommerce 购物车中有两种不同的产品。一种是门票,另一种是在用户上传文件之前必须支付的费用(由我创建的重力表格处理)。

目前,如果我将指向带有 Gravity Form 的页面的链接放在“已收到订单”页面上,如果有人只购买了一张票,他们会看到这个链接,这会让人感到困惑。

有没有办法在购买完成后根据所购买的产品获得唯一的确认页面?

如果没有,如果购买了“收费产品”(可能基于产品 ID 或类别 ID),是否存在条件标签或某种钩子或过滤器,仅在“已收到订单”页面上显示指向重力表的链接?

我确实找到了这段代码 sn-p:

https://sozot.com/how-to-hook-into-woocommerce-to-trigger-something-after-an-order-is-placed/

但是当我尝试这个时:

add_action('woocommerce_payment_complete', 'custom_process_order', 10, 1);
function custom_process_order($order_id) {
    $order = new WC_Order( $order_id );
    $myuser_id = (int)$order->user_id;
    $user_info = get_userdata($myuser_id);
    $items = $order->get_items();
    foreach ($items as $item) {
    if ($item['product_id']==154) {
echo '<h3>If you are submitting a script, please <a href="http://www.ashlandnewplays.org/wp/submit-a-script/step-2/">click here to submit your script</a>.</h3>';
        }
    }
    return $order_id;
}

订单详情屏幕上没有显示任何内容。奇怪的是,如果我尝试使用 wp_redirect 并强制重定向页面,它会“工作”,但会破坏页面并导致网站在结帐页面中出现一些奇怪的嵌入。

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    在不停地敲打之后,我终于找到了我想要的东西,所以我想我会发布它。就我而言,我想自定义带有表单链接的订单详细信息/确认页面,但仅限于购买特定产品时。

    如果你想要类似的东西,把它放在 order_details.php 模板中:

    global $woocommerce;
    
    $order = new WC_Order( $order_id );
    
    /* This two lines above should already exist, but I have them here so you can 
    see where to put the code */
    
    foreach($order->get_items() as $item) {
        $_product = get_product($item['product_id']);
        if ($item['product_id']==154) {
            // Do what you want here..replace the product ID with your product ID
            }
        }
    

    我还通过在 if 语句中插入 wp_redirect 对此进行了测试,它似乎工作得很好,所以我想您可以使用一堆 if/elseif 语句自定义此代码,这些语句根据购买的产品重定向到不同的登录页面!希望这可以帮助某人!

    【讨论】:

    猜你喜欢
    • 2018-06-25
    • 2022-01-02
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 2015-07-16
    • 2020-12-20
    • 2019-03-10
    • 1970-01-01
    相关资源
    最近更新 更多