- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要这样做,以便当人们在我们的网上商店上按下下订单时,他们将被重定向到我的帐户,但前提是类别是 XXX 、 XXX 、 XXX
但不幸的是我似乎无法让它工作
我尝试过使用&& is_product_category('Category x','Category x','Category x')
// REDIRECT AFTER PLACE ORDER BUTTON!
add_action( 'woocommerce_thankyou', 'KSVS_redirect_custom');
function KSVS_redirect_custom( $order_id ){
$order = new WC_Order( $order_id );
$url = 'https://kanselvvilselv.dk/min-konto/';
if ( $order->status != 'failed' ) {
wp_redirect($url);
exit;
}
}
无需输入 && is_product_category('Category x','Category x','Category x')
即可工作,但随后它在不应该工作的类别上工作。
最佳答案
以下代码使用专用的 template_redirect
Hook 和 WordPress has_term()
条件函数(与产品类别一起使用),当客户的订单包含定义的产品类别中的商品时,将在结帐后将客户重定向到我的帐户部分:
add_action( 'template_redirect', 'order_received_redirection_to_my_account' );
function order_received_redirection_to_my_account() {
// Only on "Order received" page
if( is_wc_endpoint_url('order-received') ) {
global $wp;
// HERE below define your product categories in the array
$categories = array('Tshirts', 'Hoodies', 'Glasses');
$order = wc_get_order( absint($wp->query_vars['order-received']) ); // Get the Order Object
$category_found = false;
// Loop theough order items
foreach( $order->get_items() as $item ){
if( has_term( $categories, 'product_cat', $item->get_product_id() ) ) {
$category_found = true;
break;
}
}
if( $category_found ) {
// My account redirection url
$my_account_redirect_url = get_permalink( get_option('woocommerce_myaccount_page_id') );
wp_redirect( $my_account_redirect_url );
exit(); // Always exit
}
}
}
代码位于事件子主题(或事件主题)的 function.php 文件中。经过测试并有效。
关于php - 如果订单商品属于特定产品类别,则结帐重定向后的 Woocommerce,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55570603/
假设我有 15 个商店,每个商店有 4 种产品和自定义价格: 每个商店不会拥有全部 4 种产品,但只能有 2 种、3 种、4 种甚至 1 种。 价格相似,但根据每个商店定制。所有商店的价格每 2-3
我这辈子似乎无法获得我想要的结构并使其正常运行,所以我一怒之下来找你们。 设置:我有一个名为 Futures_Contracts 的目录,里面有大约 30 个文件夹,全部以标的 Assets 命名,最
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题吗? 更新问题,以便 editing this post 提供事实和引用来回答它. 关闭 9 年前。 Improve
所以我已经使用 Smalltalk 大约 6 个月了(Squeak 和 Pharo),主要是做数据分析,我即将开始我的第一个 Seaside 应用程序。所以我对所有 Smalltalkers 的问题是
我选择的选项对象如下所示: { 3 : 'c', 5 : 'a', 6 : 'b', ... } 我的重复看起来像这样: {{v}} 我想按值 (v) 排序,但据我所知
什么是最好的方法(使用的算法/数据结构)来获得在购物网站上订购的前 k 项商品,相关信息在其 n 个服务器中的每一个的日志中? 我正在考虑一种方法,该方法涉及维护一个固定大小的双向链表 k 每个节点都
我正在尝试编写一个模式来验证以下 XML: AK47 The USSR's chief export back in the day, and the guer
我们正在尝试将 Android Market 集成到我们的服务中,我们需要验证用户确实是特定应用程序的所有者,我们需要自动检索该特定应用程序的销售情况。 因此,我们一直在评估 Google Check
我们有一个代表客户购物记录的数组。例如,它是这样一个数组: custA, item1, custB, item1, custA, item2, custB, item3, custC, item1,
我是一名优秀的程序员,十分优秀!