【发布时间】:2016-04-30 06:57:28
【问题描述】:
我有一个插件,它以编程方式成功地将自定义产品添加到 Woocommerce。问题是当用户第一次导航到产品页面时,没有可见的“添加到购物车”按钮。我可以通过编辑产品然后保存它来手动解决这个问题,而无需触及任何其他内容。我不知道为什么会这样,我想以编程方式解决它。
- 我点击“编辑”
- 我点击“更新”
- 然后我明白了:
如何以编程方式使“添加到购物车”按钮可见?
在“初始化”时触发:
public function createRaffleProduct(){
global $CRG_productName;
global $CRG_regularPrice;
$post = array(
'post_author' => $user_id,
'post_content' => '',
'post_status' => "publish",
'post_title' => $CRG_productName,
'post_parent' => '',
'post_type' => "product",
);
//Create post:
$post_id = wp_insert_post( $post, $wp_error );
update_post_meta( $post_id, '_visibility', 'visible' );
update_post_meta( $post_id, '_stock_status', 'instock');
update_post_meta( $post_id, 'total_sales', '0');
update_post_meta( $post_id, '_downloadable', 'no');
update_post_meta( $post_id, '_virtual', 'yes');
update_post_meta( $post_id, '_regular_price', $CRG_regularPrice);
update_post_meta( $post_id, '_sale_price', "1" );
}
【问题讨论】:
-
乍一看,我认为您可能缺少
_price元密钥。仔细查看save_post上发生的情况,并确保您使用的是所有相同的元数据。 -
感谢提及,但这不是关于 Codeception 的问题,所以我删除了标签并解释了您提及它的原因。
-
Helgathevicking,成功了!
标签: wordpress woocommerce