2014-01-30 50 views
2

我在WooCommerce购物车中有两种不同的产品。一个是票,另一个是在用户上传文件之前必须支付的费用(由我创建的重力表格处理)。有条件WooCommerce确认/订单接收页面基于产品或类别?

目前,如果我在Order Order页面上将Gravity表格链接到页面,如果有人购买了一张票,他们会看到这个链接,这会让人感到困惑。

基于购买的产品购买完成后,是否有方法可以拥有唯一的确认页?

如果没有,是否有条件标签或某种钩子或过滤器,如果购买了“收费产品”(可能基于产品ID或类别ID),它们只会在Order Received页面上显示Gravity Form的链接)?

我发现这个代码片段:

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并强制重定向页面,它“起作用”,但它会打破页面并导致网站在结帐页面中出现一些奇怪的嵌入。

回答

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语句自定义此代码,这些语句会重定向到不同的着陆页!希望这可以帮助别人!

+0

更新woocommerce时,这不会被覆盖吗?也许它应该是更好的,如果你在你的主题上覆盖这些:https://www.sellwithwp.com/customizing-woocommerce-order-emails/ – zJorge

相关问题