首先,对不起,我的英语不是最好的。我希望你能帮助我。
我正在使用 RnB - WooCommerce 预订和租赁插件开发一个 Wordpress 网站。该插件工作正常。当我尝试使用 CSV 文件中的 WP ALL IMPORT 创建我的产品时,问题就出现了。
此插件使用 2 种帖子类型的产品。
产品:与 woocommerce 相同,但具有连接到“库存”CPT 的新元数据。
库存:新的帖子类型,有每天的价格范围、数量等(所有租赁产品的数据)。
我可以插入所有必要的数据进行 2 次导入。一个用于产品,一个用于库存。问题是这个插件在数据库中有一个表,将库存项目“连接”到产品。(我猜是关系表)
表格图片: https ://desarrollodemo.tk/bebe/tabledata.png
表名:wpmp_rnb_inventory_product 内容:(2列)
inventory product
1565 1601
此表只需要库存 ID 和产品 ID。
WP ALL IMPORT 有一个钩子可以在创建/更新帖子时执行操作。http://www.wpallimport.com/documentation/advanced/action-reference/
我试过这个
首先,我得到 CTP Inventory id,当执行导入时,我通过在 Wp All Import 函数上使用此代码来获取此 id。它从 CSV 中获取标题并找到具有相同标题的库存,然后返回 id。
function id_returner($title = null) {
if ( !empty( $title ) ) {
$ids = get_page_by_title( $title, OBJECT, 'inventory' );
$id = $ids->ID;
return $id;
}
}
然后我尝试在functions.php上添加此代码以在Wp All Import创建/保存帖子时挂钩此操作。
add_action('pmxi_saved_post', 'post_saved', 10, 1);
function post_saved($id) {
$inventario = get_post_meta($id, 'id_inventario', true);
global $wpdb;
$table = $wpdb->prefix.'wpmp_rnb_inventory_product';
$data = array('column1' => $inventario, 'column2' => $id);
$format = array('%s','%d');
$wpdb->insert($table,$data,$format);
$my_id = $wpdb->insert_id;
}
但这根本行不通。我没有收到任何错误消息,但导入后表为空。
我希望你能帮帮我!。谢谢你的时间