Welcartを既存のテーマで動かす!
山下です。今回はWordpressのECプラグインwelcartを既存のテーマで動かす手順です。
大まかな手順
- 1:Welcartプラグインのインストールと有効化
- 2:Welcartのデフォルトテーマから必要なファイルをコピー
- 3:既存のテーマに上記でコピーしたファイルを移動
- 4:Welcartデフォルトテーマのfunctions.phpの中身を既存テーマのfunctions.phpへ追加
- 5:商品一覧ページなどを作成
- 6:商品詳細ページのテンプレートを既存テーマに合わせて修正
- 7:カートの遷移画面などのテンプレートを既存テーマに合わせて修正
- 8:会員機能を利用する場合は該当するテンプレートを既存のテーマに合わせて修正
Welcartプラグインのインストールと有効化
WordPressの管理画面のプラグインの新規追加からwelcartで検索してインストール
インストールが終わったら有効化
※プラグインのインストール手順などは割愛します。
Welcartのデフォルトテーマから必要なファイルをコピー
プラグインをインストールするとテーマフォルダの中に「welcart_default」がインストールされています。この中のファイルを既存テーマへコピーします。
welcartのデフォルトテーマの中の「wc_templates」フォルダは丸ごとコピーして既存テーマへ移動
welcartのデフォルトテーマの中の「functions.php」の中身を既存テーマのfunctions.phpに追加
必要であればwelcartのデフォルトテーマの中の「usces_cart.css」も既存テーマの同じ階層にコピーして移動
Welcartデフォルトテーマのfunctions.phpの中身を既存テーマのfunctions.phpへ追加
functions.phpはファイルではなく中身をコピーして既存テーマのfunctions.phpに張り付ける
↓下記だけを追加する↓
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
<?php /** * <meta content="charset=UTF-8"> * @package Welcart * @subpackage Welcart Default Theme */ if(!defined('USCES_VERSION')) return; /*********************************************************** * welcart_setup ***********************************************************/ add_action( 'after_setup_theme', 'welcart_setup' ); if ( ! function_exists( 'welcart_setup' ) ): function welcart_setup() { load_theme_textdomain( 'uscestheme', TEMPLATEPATH . '/languages' ); $GLOBALS['content_width'] = 770; add_theme_support('title-tag'); register_nav_menus( array( 'header' => __('Header Navigation', 'usces' ), 'footer' => __('Footer Navigation', 'usces' ), ) ); } endif; /*********************************************************** * welcart_page_menu_args ***********************************************************/ function welcart_page_menu_args( $args ) { $args['show_home'] = true; return $args; } add_filter( 'wp_page_menu_args', 'welcart_page_menu_args' ); /*********************************************************** * sidebar ***********************************************************/ if ( function_exists('register_sidebar') ) { // Area 1, HomeLeft. register_sidebar(array( 'name' => __( 'Home Left', 'uscestheme' ), 'id' => 'homeleft-widget-area', 'description' => __( 'home left sidebar widget area', 'uscestheme' ), 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<div class="widget_title">', 'after_title' => '</div>', )); // Area 2, HomeRight. register_sidebar(array( 'name' => __( 'Home Right', 'uscestheme' ), 'id' => 'homeright-widget-area', 'description' => __( 'home right sidebar widget area', 'uscestheme' ), 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<div class="widget_title">', 'after_title' => '</div>', )); // Area 3, OtherLeft. register_sidebar(array( 'name' => __( 'Other Left', 'uscestheme' ), 'id' => 'otherleft-widget-area', 'description' => __( 'other left sidebar widget area', 'uscestheme' ), 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<div class="widget_title">', 'after_title' => '</div>', )); // Area 4, CartMemberLeft. register_sidebar(array( 'name' => __( 'CartMemberLeft', 'uscestheme' ), 'id' => 'cartmemberleft-widget-area', 'description' => __( 'cart or member left sidebar widget area', 'uscestheme' ), 'before_widget' => '<li id="%1$s" class="widget %2$s">', 'after_widget' => '</li>', 'before_title' => '<div class="widget_title">', 'after_title' => '</div>', )); } /*********************************************************** * widget ***********************************************************/ add_filter('widget_categories_dropdown_args', 'welcart_categories_args'); add_filter('widget_categories_args', 'welcart_categories_args'); function welcart_categories_args( $args ){ global $usces; $ids = $usces->get_item_cat_ids(); $ids[] = USCES_ITEM_CAT_PARENT_ID; $args['exclude'] = $ids; return $args; } add_filter('getarchives_where', 'welcart_getarchives_where'); function welcart_getarchives_where( $r ){ $where = "WHERE post_type = 'post' AND post_status = 'publish' AND post_mime_type <> 'item' "; return $where; } add_filter('widget_tag_cloud_args', 'welcart_tag_cloud_args'); function welcart_tag_cloud_args( $args ){ global $usces; if( 'category' == $args['taxonomy']){ $ids = $usces->get_item_cat_ids(); $ids[] = USCES_ITEM_CAT_PARENT_ID; $args['exclude'] = $ids; }else if( 'post_tag' == $args['taxonomy']){ $ids = $usces->get_item_post_ids(); $tobs = wp_get_object_terms($ids, 'post_tag'); foreach( $tobs as $ob ){ $tids[] = $ob->term_id; } $args['exclude'] = $tids; } return $args; } /*********************************************************** * excerpt ***********************************************************/ if ( ! function_exists( 'welcart_assistance_excerpt_length' ) ) { function welcart_assistance_excerpt_length( $length ) { return 10; } } if ( ! function_exists( 'welcart_assistance_excerpt_mblength' ) ) { function welcart_assistance_excerpt_mblength( $length ) { return 40; } } if ( ! function_exists( 'welcart_excerpt_length' ) ) { function welcart_excerpt_length( $length ) { return 40; } } add_filter( 'excerpt_length', 'welcart_excerpt_length' ); if ( ! function_exists( 'welcart_excerpt_mblength' ) ) { function welcart_excerpt_mblength( $length ) { return 110; } } add_filter( 'excerpt_mblength', 'welcart_excerpt_mblength' ); if ( ! function_exists( 'welcart_continue_reading_link' ) ) { function welcart_continue_reading_link() { return ' <a href="'. get_permalink() . '">' . __( 'Continue reading <span class="meta-nav">→</span>', 'uscestheme' ) . '</a>'; } } if ( ! function_exists( 'welcart_auto_excerpt_more' ) ) { function welcart_auto_excerpt_more( $more ) { return ' …' . welcart_continue_reading_link(); } } //add_filter( 'excerpt_more', 'welcart_auto_excerpt_more' ); if ( ! function_exists( 'welcart_custom_excerpt_more' ) ) { function welcart_custom_excerpt_more( $output ) { if ( has_excerpt() && ! is_attachment() ) { $output .= welcart_continue_reading_link(); } return $output; } } //add_filter( 'get_the_excerpt', 'welcart_custom_excerpt_more' ); /*********************************************************** * SSL ***********************************************************/ if( $usces->options['use_ssl'] ){ add_action('init', 'usces_ob_start'); function usces_ob_start(){ global $usces; if( $usces->use_ssl && ($usces->is_cart_or_member_page($_SERVER['REQUEST_URI']) || $usces->is_inquiry_page($_SERVER['REQUEST_URI'])) ) ob_start('usces_ob_callback'); } if ( ! function_exists( 'usces_ob_callback' ) ) { function usces_ob_callback($buffer){ global $usces; $pattern = array( '|(<[^<]*)href=\"'.get_option('siteurl').'([^>]*)\.css([^>]*>)|', '|(<[^<]*)src=\"'.get_option('siteurl').'([^>]*>)|' ); $replacement = array( '${1}href="'.USCES_SSL_URL_ADMIN.'${2}.css${3}', '${1}src="'.USCES_SSL_URL_ADMIN.'${2}' ); $buffer = preg_replace($pattern, $replacement, $buffer); return $buffer; } } } ?> |
商品一覧ページなどを作成
https://www.welcart.com/community/archives/759
上記など参考にしながらitem.phpかなんかで商品一覧ページを作成しておきましょう。
商品詳細ページのテンプレートを既存テーマに合わせて修正
wc_templatesフォルダの中にあるwc_item_single.phpが商品詳細ページのテンプレートです。既存のテーマに合わせて修正しましょう。
カートの遷移画面などのテンプレートを既存テーマに合わせて修正
wc_templates/cart/の中にあるファイルがカートの遷移画面のテンプレートです。こちらも既存のテーマに合わせて修正しておきましょう。
会員機能を利用する場合は該当するテンプレートを既存のテーマに合わせて修正
wc_templates/member/の中にあるファイルは会員機能を利用した時に必要になるテンプレートです。こちらも既存のテーマに合わせて修正しておきましょう。
後はカートの中を見るボタンや、会員ログインボタンなどネットショップに必要な項目を既存テーマに追加してネットショップとして機能するようにしましょう。
以上ざっくりですが既存テーマでWelcartを動かす手順でした。