0

我使用 WP-All Import 和 WooCommerce 插件在 WooCommerce 中导入产品。在原始 xml 中,我有 3 个针对不同用户角色的折扣类别。使用 WooCommerce 的客户特定定价插件 ( https://wisdmlabs.com/woocommerce-user-specific-pricing-extension/ ) 我可以为这些角色显示不同的价格。

这个插件将他的数据保存到一个单独的表(wp_wusp_role_pricing_mapping),这意味着 WP-All Import 不能直接插入数据。

但是,WP All Import 有一个钩子pmxi_saved_post,每次保存或更新帖子时都会调用该钩子。(http://www.wpallimport.com/documentation/advanced/action-reference/

在该函数中,我必须能够将记录插入到 wusp_role_price_mapping 表中,因为我需要 post_id,但是,这是我的问题:我还需要来自 XML 的原始数据,其中单独的折扣规则可用。我可以在钩子操作中访问该数据吗?

为了您的信息,这是数据在 xml 中的外观,以及它必须如何保存在数据库中。

<Korting>
    <KortingCategorie>EH Markt 71 %</KortingCategorie>
    <Percentage>40</Percentage>
    <Prijs>0,0000</Prijs>

    <KortingCategorie>EH winkel 35%</KortingCategorie>
    <Percentage>40</Percentage>
    <Prijs>0,0000</Prijs>

    <KortingCategorie>EH Winkel 45%</KortingCategorie>
    <Percentage>40</Percentage>
    <Prijs>0,0000</Prijs>

    <KortingCategorie>EH Winkel 50%</KortingCategorie>
    <Percentage>40</Percentage>
    <Prijs>0,0000</Prijs>
</Korting>

如您所见,折扣类别/用户角色的名称(KortingCategorie在 xml 中)并不总是包含正确的折扣百分比,而且每个产品的折扣也不同。

+----+--------------+---------+---------+------------------------+------------+
| id |     role     |  price  | min_qty | flat_or_discount_price | product_id |
+----+--------------+---------+---------+------------------------+------------+
|  1 | eh_winkel_50 | 40.0000 |       1 |                      2 |       5445 |
|  2 | eh_winkel_45 | 40.0000 |       1 |                      2 |       5445 |
|  3 | eh_markt     | 40.0000 |       1 |                      2 |       5445 |
+----+--------------+---------+---------+------------------------+------------+
4

1 回答 1

0

刚刚找到另一个解决方案:

通过导入,我将折扣组添加到自定义字段,并使用钩子和get_post_metaandwpdb->insert()函数在正确的位置添加正确的值。

于 2017-03-08T12:56:33.840 回答