向Woocommerce添加自定义帖子类型/帖子 [英] Adding custom post type / post to Woocommerce
问题描述
我有一个个人主题"A" ,我希望它也可以在没有Woocommerce的情况下使用. 添加 Woocommerce"WC" 插件后,我会将A产品与WC集成在一起.我有一个称为对象"的自定义帖子类型,如何通过WC使对象"可购买?
I have a personal theme "A" and I want that it can also work without Woocommerce. When Woocommerce "WC" plugin is added I would integrate A products with WC. I have a custom post type called "objects", how can I make "object" buyable throught WC?
我已经在StackOverflow上看到了这个答案将自定义帖子类型添加到Woocommerce 最终解决方案提供了一个免费的(不再可用)插件来解决.
I've alredy seen this answer on StackOverflow Adding Custom Post Types to Woocommerce Where the solution in the end gives a free (not anymore) plugin to resolve.
我更愿意在没有插件帮助的情况下自行完成此操作.我很好奇,预包装解决方案不是我想要的.
推荐答案
我们可以尝试一件简单的事情..您希望使用自定义帖子类型来存储您的产品,并且当WooCommerce集成时,可以在您的自定义帖子类型中添加产品作为woocommerce产品..
We can try a easy thing .. you want a custom post type to store your products and when WooCommerce is integrated the added products in your custom post type can work as woocommerce products ..
-
检查是否安装了woocommerce.
Check if woocommerce is installed ot not.
如果没有,则创建一个自定义帖子类型为产品"(类似于woocommerce).
If not, then Create a custom post type as 'product' (similar to woocommerce).
要检查woocommerce是否处于活动状态,请使用此代码
To check whether woocommerce is active or not use this code
<?php
if ( class_exists( 'WooCommerce' ) ) {
// code that requires WooCommerce
} else {
// you don't appear to have WooCommerce activated
}
?>
这篇关于向Woocommerce添加自定义帖子类型/帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!