【发布时间】:2016-02-24 12:58:42
【问题描述】:
如果客户没有订单,我想在我的帐户中显示一条消息我想显示“当前没有订单”。 我猜有一个函数可以用来在某个地方挂钩? 进行了很好的搜索,但找不到任何可以让我开始的东西。 谢谢。
【问题讨论】:
标签: function woocommerce hook message orders
如果客户没有订单,我想在我的帐户中显示一条消息我想显示“当前没有订单”。 我猜有一个函数可以用来在某个地方挂钩? 进行了很好的搜索,但找不到任何可以让我开始的东西。 谢谢。
【问题讨论】:
标签: function woocommerce hook message orders
从this tutorial修改我认为这会起作用:
function wc_get_customer_orders() {
// Get all customer orders
$customer_orders = get_posts( array(
'numberposts' => 1,
'meta_key' => '_customer_user',
'meta_value' => get_current_user_id(),
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
$customer = wp_get_current_user();
// Text for our message
$notice_text = sprintf( 'Hey %1$s 😀 We noticed you haven\'t placed any orders with us.', $customer->display_name );
// Display our notice if the customer has no orders
if ( count( $customer_orders ) == 0 ) {
wc_print_notice( $notice_text, 'notice' );
}
}
add_action( 'woocommerce_before_my_account', 'wc_get_customer_orders' );
基本上,在帐户页面上,我们查询当前登录用户的单个订单。如果我们没有收到订单,我们会出示通知。
【讨论】:
woocommerce_before_my_account 不同的钩子即可。或者将该钩子添加到您的其他标签页。
wc_get_customer_orders(),我认为甚至可以直接调用它。但是为什么要使用外部页面而不是 WP 页面呢?
将 my-orders.php 复制到本地文件夹并添加 else 子句:
else{
echo "No orders";
}
这可以使用 WC css 设置样式
【讨论】: