WordPress WooCommerce检测某个产品ID Product ID 是否在订单中 代码实例

来源: 老季博客
日期: 2022-6-1
作者: 腾讯云/服务器VPS推荐评测/Vultr
阅读数: 52

在WordPress的主题WooCommerce商城开发插件中,我们需要检测一个产品id是否在某个订单中,下面我们记录一下代码实例

function check_order_product_id($order_id,$the_product_id)
{
    $order = wc_get_order((int)$order_id);
    $items = $order->get_items();
    foreach ($items as $item_id => $item) {
        $product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
        if ($product_id === (int)$the_product_id) {
            return true;
        }
    }
    return false;
}
链接到文章: https://jiloc.com/47795.html

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注