【问题标题】:Create a coupon in Woocommerce with mysql使用 mysql 在 Woocommerce 中创建优惠券
【发布时间】:2019-01-30 15:34:28
【问题描述】:

我有两个不同的网站。 Site1 是 wordpress 网站。 Site2 是另一个站点。我想要做的是从site2 在site1 的数据库中创建一张优惠券。我已成功连接到 site1 的数据库,并且可以进行 mysql 查询。现在,如何仅使用 mysql 从 site2 创建 woocommerce 优惠券。 (site2内置在node.js中)

我想做这样的事情(这当然行不通,但是这样的事情)

INSERT INTO wp58_posts(post_title, post_status, comment_status,ping_status, post_password, post_name, post_type )values('testcoupon', 'publish', 'closed', 'closed', 'testcoupon', 'shop_coupon');

【问题讨论】:

  • 如果您需要帮助,请发布您已经尝试过的代码。
  • 我不知道怎么做,因此没有编码
  • Stack Overflow 不是您给我们带来问题并期望我们为您编写自定义解决方案的地方。如果您无法编写自己的代码,我建议您聘请专业的开发人员。
  • 对于我写的不好的问题,我很抱歉。我要找的是以前已经做过或比我更了解 Wordpress 数据库的人。我正处于学习阶段,希望有更多知识的人来回答。

标签: mysql sql wordpress woocommerce


【解决方案1】:

所有魔法 - Create a coupon programatically

或者

$coupon_code = 'UNIQUECODE'; // Code
$amount = '10'; // Amount
$discount_type = 'fixed_cart'; // Type: fixed_cart, percent, fixed_product, percent_product
$wp_prefix = 'wp_'; 
$post_author = 1;  // post author ID

$sql = "INSERT INTO `{$wp_prefix}posts` 
(`post_title`, `post_content`, `post_status`, `post_author`, `post_type`) 
  VALUES 
({$coupon_code}, '', 'publish', {$post_author}, 'shop_coupon')";

$coupon_id = $last_inser_id;

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'discount_type', {$discount_type})";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'coupon_amount', {$amount})";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'individual_use', 'no')";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'product_ids', '')";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'exclude_product_ids', '')";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'usage_limit', '')";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'expiry_date', '')";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'apply_before_tax', 'yes')";

$sql = "INSERT INTO `{$wp_prefix}postmeta` 
(`post_id`, `meta_key`, `meta_value`) 
  VALUES 
({$coupon_id}, 'free_shipping', 'no')";

【讨论】:

  • 我试过了,但是没有用 INSERT INTO wp58_posts(post_title, post_content, post_status ,post_author,post_type) values('testcoupon', '', 'publish', '2', 'shop_coupon' );我得到错误代码:1292。不正确的日期时间值:第 1 行的列“post_date”的“0000-00-00 00:00:00”
  • 在此列中使用NOW()
  • 它适用于那个 col,现在我得到了错误代码:1292。不正确的日期时间值:第 1 行的列 'post_date_gmt' 的日期时间值不正确
  • 对所有日期时间字段使用NOW()
  • nvm 我用这个查询修复了它 INSERT INTO wordpress.wp58_posts(post_date,post_date_gmt,post_modified,post_modified_gmt,post_excerpt,to_ping,pinged,post_content_filtered,post_title, post_content, post_status ,post_author,post_type) 值(现在(),NOW(),NOW(),NOW(),'testhuheuhe','','','','testcoupon','','publish','2','shop_coupon'); /*select * from wordpress.wp58_posts where post_type = "shop_coupon";现在我只需要修复 postmeta 对吗?
猜你喜欢
  • 2022-01-09
  • 2014-02-26
  • 1970-01-01
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多