0

对于我的一个客户,我重构了一些不再起作用的代码。该脚本从 CSV 导入(变量)产品。一切正常,产品和属性被导入并在后端完整显示。

奇怪的是,产品没有出现在网站的前端。也就是说,直到我们从后端只保存一次(实际上,只需按下该产品的保存按钮而不做任何其他事情)。

在重构过程中,我们发现了这段代码;

  $test = new WC_Product($id);
  $test->variable_product_sync();
  $test = null;

这不再适用于新的 WooCommerce,现在一切都是静态的。我们现在如何实现这个功能?我们不确定这是否可以解决。

4

2 回答 2

0

啊,找到了。您可以删除 variable_product_sync。确保通过 update_post_meta 将元 _visible 设置为“可见”。

于 2013-10-11T09:49:29.843 回答
0
include_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-content/plugins/woocommerce/woocommerce.php' );

$product_variable = new WC_Product_Variable($product_id);
$product_variable->sync($product_id);
wc_delete_product_transients($product_id);
于 2016-11-17T09:00:27.483 回答