我希望我的插件在激活时自动创建自定义帖子类型。
这是我的代码
register_activation_hook(__FILE__, 'activate_myplugin');
function activate_myplugin() {
add_action('init', 'create_custom_type_post');
function create_custom_type_post() {
register_post_type('customposttype', array(
'label' => 'my custom type post',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array(
'slug' => 'mycustomposttype',
'with_front' => false
),
'query_var' => true,
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'revisions',
'thumbnail',
'author',
'page-attributes'
)
)
);
}
Run Code Online (Sandbox Code Playgroud)
}
以及停用时如何将其删除?
我需要一个 if else 语句来检查 woocommerce 上的产品是否简单或可变,以便我可以为自定义产品页面显示正确的“添加到购物车”按钮。
div class="six">
<?php
if( $product->is_type( 'simple' ) ){ ?>
<p>single</p>
<?php } elseif( $product->is_type( 'variable' ) ){ ?>
<p>variable</p>
<?php } ?>
</div>
Run Code Online (Sandbox Code Playgroud)
但是收到此错误消息
Fatal error: Uncaught Error: Call to a member function is_type() on string in /Applications/MAMP/htdocs/jollybrewer/wp-content/plugins/woocommerce/templates/content-single-product.php:48 Stack trace: #0 /Applications/MAMP/htdocs/jollybrewer/wp-includes/template.php(690): require() #1 /Applications/MAMP/htdocs/jollybrewer/wp-content/plugins/woocommerce/includes/wc-core-functions.php(180): load_template('/Applications/M...', false) #2 /Applications/MAMP/htdocs/jollybrewer/wp-content/themes/jolly/woocommerce/single-product.php(41): wc_get_template_part('content', 'single-product') #3 /Applications/MAMP/htdocs/jollybrewer/wp-includes/template-loader.php(74): include('/Applications/M...') #4 /Applications/MAMP/htdocs/jollybrewer/wp-blog-header.php(19): require_once('/Applications/M...') #5 /Applications/MAMP/htdocs/jollybrewer/index.php(17): require('/Applications/M...') #6 {main} thrown in /Applications/MAMP/htdocs/jollybrewer/wp-content/plugins/woocommerce/templates/content-single-product.php on line 48
Run Code Online (Sandbox Code Playgroud)