如何删除插件中的术语? woocommerce

时间:2014-11-14 07:10:11

标签: database wordpress woocommerce

我正在创建一个带有插件挂钩的插件,当插件激活它创建产品属性它工作正常我也添加属性术语它也工作正常和插件停用我删除它但我只看到属性删除但条款不删除。< / p>

我使用此代码删除属于其正常工作的属性

enter code here
// attributes parameters
$wpm_attributes = array(
    array(
        'label' => 'Size',
        'name' => 'size',
        'type' => 'select',
    ),
    array(
        'label' => 'Color',
        'name' => 'color',
        'type' => 'select',
    )
);

foreach ( $wpm_attributes as $attr ) {
    $attribute = array(
        'attribute_label'   => $attr['label'],
        'attribute_name'    => $attr['name'],
        'attribute_type'    => $attr['type'],
        'attribute_orderby' => 'menu_order'
    );
    $wpdb->delete( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute );
    delete_transient( 'wc_attribute_taxonomies' );
}

1 个答案:

答案 0 :(得分:0)

I recommend not deleting the terms at the point of deactivation.

Instead why don't you delete the terms at the point of uninstallation?

You can use the uninstall hook:
http://codex.wordpress.org/Function_Reference/register_uninstall_hook

Or bypass that.

The plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook.

This may be easier to manage code wise and sometimes people would like to deactivate a plugin and not lose all their data.