Woocommerceの属性に「親」と「子」を割り当てたい!プラグインなしで可能にする方法。

Woocommerceの「属性」にカテゴリーのように「親」と「子」を作成できればいいと思ったことはありませんか?

かつてはこの機能がありましたがバージョンアップを経てなくなってしまいました。

現在のバージョンでも利用可能にするためには、テーマ(子テーマ使用時は子テーマ)の「functions.php」に下記コードを追記してください。

if( function_exists( 'WC' ) ){
    add_action( 'init', 'ag_woocommerce_register_taxonomies_hack', 4 );

    if( ! function_exists( 'ag_woocommerce_register_taxonomies_hack' ) ){
        function ag_woocommerce_register_taxonomies_hack(){
            if( $attribute_taxonomies = wc_get_attribute_taxonomies() ) {
                foreach ($attribute_taxonomies as $tax) {
                    if ($name = wc_attribute_taxonomy_name($tax->attribute_name)) {
                        add_filter( "woocommerce_taxonomy_args_{$name}", 'ag_woocommerce_taxonomy_product_attribute_args' );
                    }
                }
            }
        }
    }

    if( ! function_exists( 'ag_woocommerce_taxonomy_product_attribute_args' ) ){
        function ag_woocommerce_taxonomy_product_attribute_args( $taxonomy_data ){
            $taxonomy_data['hierarchical'] = true;
            return $taxonomy_data;
        }
    }
}

Web コード プラグインなし

長いリンク(URL)がはみ出すときのCSS。スマホでも対策OK!

スマートフォンで見ると、長いリ...

続きを見る

Web Wordpress コード スピード プラグインなし

プラグインなし!目次を実装する方法。|WordPress

WordPressで、プラグイ...

続きを見る

Web コード プラグインなし

wp-config.phpにとりあえず書いとくやつ。

define( 'WP_DEB...

続きを見る

コード

サーバー内でzipファイルを解凍する方法

解凍したいファイルを「exam...

続きを見る

コメントを残す