ITおじさん

ITと戦うおじさんの備忘録。PHPとWordPress頑張ってます。

WooCommerce日本語テーマ Japacartメモ 

日本語に対応したWordPressテーマ Japacart

  •  商品サムネイルの下にカートに追加するボタンが無い。詳細ページへ行くのはわかりやすい。
  •  ページ幅が100%にならない
  • 一部英語のまま?(WooCommerce側の問題?)
  •  【追記】テーマ販売アフィリエイトできる(ユーザー限定?)
  •  1カラム表示でもOK
  • マニュアルに銀行振込の説明あり
  • メールテンプレートは自力で編集
  • 支払い画面で国選択が非表示にできる

 

 

WooCommerce関連機能

ナビゲーションリンク

ヘッダーの「マイアカウント」リンクの表示/非表示に設定することができる。

 

設定項目 設定内容
マイアカウントリンクの表示/非表示 ヘッダー&モバイルナビゲーションのマイアカウントリンクの表示/非表示

 

支払いフォームの入力項目(物販)

配送がともなう商品がカートに入っている場合の購入支払い画面の入力フィールドの設定

項目 設定内容
支払いフォーム 国フィールドの表示/非表示
カートページの送料自動計算機 市区町村フィールドの表示/非表示
郵便番号フィールドの表示/非表示

支払いフォームの入力項目(デジタル商品)

デジタル商品だけがカートに入っている場合の購入画面の各入力フィールドの表示設定。

項目 設定内容
支払いフォーム

“会社名”フィールドの非表示
“国または地域”フィールドの非表示
“郵便番号”フィールドの非表示
都道府県”フィールドの非表示
“市区町村”フィールドの非表示
“番地”フィールドの非表示
“アパート名、棟名、部屋番号など”フィールドの非表示
“電話番号”フィールドの非表示
“注文メモ”フィールドの非表示

 

関連商品、アップセル&クロスセルの表示設定

関連商品、アップセル&クロスセルの表示を設定

項目 設定内容
関連商品 表示/非表示の切り替え、カラム数、表示数(上限)
アップセル カラム数
クロスセル カラム数

 

WooCommerceのテキスト変更

重くならないようにあまり使わないこと

項目 設定内容
テキスト変更 変更前と変更後テキストフィールドのセットが合計20個

 

クレジットカードアイコン

JCBアイコンがダブル表示?

項目 設定内容
Diners / Discoverカード カードアイコンの表示/非表示

商品バッジ

商品サムネイルにバッジを付けることができる

Japacart × WooCommerce Shortcodes 

Japacartのオリジナルブロック

WooCommerceのショートコードを自動生成することができる。

ブロック名 機能/設定項目
最新の商品 カテゴリー検索窓&絞り込み、カラム数の変更、表示数(上限)の設定、スライドショーのオン/オフ
商品手動選択 商品検索窓、カラム数の変更、スライドショーのオン/オフ、並び順(日付/注文数/評価/タイトル/ランダム)
セール商品 カテゴリー検索窓&絞り込み、カラム数の変更、表示数(上限)の設定、スライドショーのオン/オフ、並び順(日付/注文数/評価/タイトル/ランダム)
売れ筋商品 カテゴリー検索窓&絞り込み、カラム数の変更、表示数(上限)の設定、スライドショーのオン/オフ
おすすめ商品 カテゴリー検索窓&絞り込み、カラム数の変更、表示数(上限)の設定、スライドショーのオン/オフ
カテゴリー別商品 カテゴリー検索窓&絞り込み、カラム数の変更、表示数(上限)の設定、スライドショーのオン/オフ
タグ別商品 タグ検索窓&絞り込み、カラム数の変更、表示数(上限)の設定、スライドショーのオン/オフ
すべてのカテゴリー 子カテゴリーの表示/非表示、カラム数の変更、スライドショーのオン/オフ
カテゴリー手動選択 カテゴリー検索窓、カラム数の変更、スライドショーのオン/オフ、並び順(選択順/カテゴリー名)

 

MW WP FORMを閲覧できる権限をユーザー毎に設定

各ユーザーIDでログインする MW WP FORMを複製して登録し直す。

下記実行で自分が複製したもの以外は見れなくなる。

```

function my_remove_editor_caps(){
$role = get_role( 'editor' );
$role->remove_cap( 'edit_others_pages' ); //固定ページ
$role->remove_cap( 'edit_others_posts' ); //投稿ページ
}
add_action( 'admin_init', 'my_remove_editor_caps' );

```

 

少し面倒くさい

WordPress特定の管理画面で実行 $hook_suffix等

#WordPressの管理バーのメニューに $hook_suffix の値を表示

```

function admin_bar_menu_hook_suffix( $wp_admin_bar ) {
global $hook_suffix;
if ( ! is_admin() ) return;

$wp_admin_bar->add_menu(array(
'id' => 'hook-suffix',
'title' => '$hook_suffix : ' . $hook_suffix,
'parent' => false,
));
}
add_action( 'admin_bar_menu', 'admin_bar_menu_hook_suffix', 100 );

```

WooCommerce Conditional 条件判定

WooCommerceで条件式作るとき

 

 

if (class_exists('Woocommerce')) {
$shop_id = wc_get_page_id('shop');
}

is_product_taxonomy()

 

//https://docs.woocommerce.com/document/create-a-plugin/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Put your plugin code here
}

 

 

管理画面でカテゴリーを1つだけチェックできるように、不要なものを非表示

functions.php

//***--- 管理画面用JS読み込み true=body直前 false=head
//my_admin_script.jsはテーマファイル内/js/にアップロード
function my_admin_script(){
wp_enqueue_script( 'my_admin_script', get_template_directory_uri().'/js/my_admin_script.js', array('jquery'), '', true);
}
add_action( 'admin_enqueue_scripts', 'my_admin_script' );

テーマフォルダ内に/js/フォルダを作りmy_admin_script.jsをアップロード

// 管理画面要JS



jQuery(function($){

// 投稿画面のカテゴリーを1つだけ選択に制限
var cat_checklist = $('.categorychecklist input[type=checkbox]');
cat_checklist.click( function() {
    $(this).parents('.categorychecklist').find('input[type=checkbox]').attr('checked', false);
    $(this).attr('checked', true);
});

// クイック編集のカテゴリーを1つだけ選択に制限
var quickedit_cat_checklist = $('.cat-checklist input[type=checkbox]');
quickedit_cat_checklist.click( function() {
    $(this).parents('.cat-checklist').find('input[type=checkbox]').attr('checked', false);
    $(this).attr('checked', true);
});

//「よく使うもの」を非表示に
$('.category-tabs li.hide-if-no-js').css('display','none');

//「新規カテゴリーを追加」を非表示に
$('.taxonomy-add-new').css('display','none');

//タグボックスを非表示に
$('#tagsdiv-post_tag').css('display','none');

//カテゴリーボックスの縦幅を大きく
$('.categorydiv div.tabs-panel').css({'max-height':'100%'});

// クイック編集のタグ、コメントを許可、トラックバック/ピンバックを許可を非表示に
$('.inline-edit-col-right .inline-edit-tags, .inline-edit-col-right input[name="comment_status"], .inline-edit-col-right input[name="ping_status"], .inline-edit-col-right input[name="comment_status"]+.checkbox-title, .inline-edit-col-right input[name="ping_status"]+.checkbox-title').css('display','none');


});

管理画面に更新日枠を追加する

init.php

管理画面css読み込み

//***--- 管理画面用JSとCSS読み込み true=body直前 false=head
//my_admin_script.jsはテーマファイル内/js/にアップロード
//my_admin_style.cssはテーマファイル内/css/にアップロード
function my_admin_script(){
    wp_enqueue_script( 'my_admin_script', get_template_directory_uri().'/js/my_admin_script.js', array('jquery'), '', true);
    wp_enqueue_style('admin-styles', get_template_directory_uri().'/css/my_admin_style.css');
}
add_action( 'admin_enqueue_scripts', 'my_admin_script' );

my_admin_style.css

.modified-box {
    padding-top: 5px;
    overflow: hidden;
}
.modified-box-date {
    font-weight: bold;
}
.modified-time-timestamp-wrap {
    margin-bottom: 15px;
}
.modified-time {
    margin-top: 5px; 
    padding: 2px 0 1px 0;
    display: block !important;
    height: auto !important;
}
.modified-time:before { 
    font: normal 20px/1 'dashicons'; 
    content: '\f145'; 
    color: #888; 
    padding: 0 5px 0 0; 
    top: -1px; 
    left: -1px; 
    position: relative; 
    vertical-align: top; 
}
select.mm { 
    height: 21px; 
    line-height: 14px; 
    padding: 0; 
    vertical-align: top;
    font-size: 12px;
}
#aa_mod, #jj_mod, #hh_mod, #mn_mod { 
    padding: 1px; 
    font-size: 12px; 
}
#jj_mod, #hh_mod, #mn_mod { 
    width: 2em; 
}
#aa_mod { 
    width: 3.4em;
}

custom-post.php

//***--- ブログ管理画面の「公開」の上に「更新日時」枠を追加

// メタボックスを表示 メタボックス内のソースはmy_custom_mod_dateで設定
if( !function_exists( 'my_add_meta_box' ) ):
    function my_add_meta_box() {
        add_meta_box( 'update_level', '更新日時', 'my_custom_mod_date', 'post', 'side', 'default' );
    }
    add_action( 'admin_menu', 'my_add_meta_box' );
    endif;
    
    // 更新日フォーム
    if( !function_exists( 'my_custom_mod_date' )):
    function my_custom_mod_date() {
        global $post;
    ?>
    <div class="modified-box">    
    <input id="update_level_edit" name="update_level" type="radio" value="edit" checked="checked" />手動で設定
    <?php
        if( get_the_modified_date( 'c' ) ) {
            $stamp = '更新日時: <span class="modified-box-date">' . get_the_modified_date( __( 'M j, Y @ H:i' ) ) . '</span>';
        }
        else {
            $stamp = '更新日時: <span class="modified-box-date">未更新</span>';
        }
        $date = date_i18n( get_option('date_format') . ' @ ' . get_option('time_format'), strtotime( $post->post_modified ) );
    ?>
    <span class="modified-time"><?php printf( $stamp, $date ); ?></span>
    <div class="modified-time-timestamp-wrap" onkeydown="document.querySelector('#update_level_edit').checked=true" onclick="document.querySelector('#update_level_edit').checked=true">
    <?php my_time_mod_form(); ?>
    </div>
    <div><input name="update_level" type="radio" value="update"/>現在の日付に更新</div>
    </div>
    <?php
    }
    endif;
    
    //更新日時変更の入力フォーム
    if( !function_exists( 'my_time_mod_form' ) ):
    function my_time_mod_form() {
        global $wp_locale, $post;
    
        $tab_index = 0;
        $tab_index_attribute = '';
        if ( (int) $tab_index > 0 ) {
            $tab_index_attribute = ' tabindex="' . $tab_index . '"';
        }
        //mysql2date = phpのdate()が受け付ける書式に変換
        $jj_mod = mysql2date( 'd', $post->post_modified, false );
        $mm_mod = mysql2date( 'm', $post->post_modified, false );
        $aa_mod = mysql2date( 'Y', $post->post_modified, false );
        $hh_mod = mysql2date( 'H', $post->post_modified, false );
        $mn_mod = mysql2date( 'i', $post->post_modified, false );
        $ss_mod = mysql2date( 's', $post->post_modified, false );
    
        $year = '<label for="aa_mod" class="screen-reader-text">年' .
            '</label><input type="text" id="aa_mod" name="aa_mod" value="' .
            $aa_mod . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" />年';
    
        $month = '<label for="mm_mod" class="screen-reader-text">月' .
            '</label><select id="mm_mod" class="mm" name="mm_mod"' . $tab_index_attribute . ">\n";
        for( $i = 1; $i < 13; $i = $i +1 ) {
            $monthnum = zeroise($i, 2);
            $month .= "\t\t\t" . '<option value="' . $monthnum . '" ' . selected( $monthnum, $mm_mod, false ) . '>';
            $month .= $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) );
            $month .= "</option>\n";
        }
        $month .= '</select>';
    
        $day = '<label for="jj_mod" class="screen-reader-text">日' .
            '</label><input type="text" id="jj_mod" name="jj_mod" value="' .
            $jj_mod . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />日';
        $hour = '<label for="hh_mod" class="screen-reader-text">時' .
            '</label><input type="text" id="hh_mod" name="hh_mod" value="' . $hh_mod .
            '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
        $minute = '<label for="mn_mod" class="screen-reader-text">分' .
            '</label><input type="text" id="mn_mod" name="mn_mod" value="' . $mn_mod .
            '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" />';
    
        printf( '%1$s %2$s %3$s @ %4$s : %5$s', $year, $month, $day, $hour, $minute );
        echo '<input type="hidden" id="ss_mod" name="ss_mod" value="' . $ss_mod . '" />';
    }
    endif;
    
    // それぞれの更新日時に変更する */
    if( !function_exists( 'my_insert_post_data' )):
    function my_insert_post_data( $data, $postarr ){
        $mydata = isset( $_POST['update_level'] ) ? $_POST['update_level'] : null;
    
        if( $mydata === 'edit' ) {
            $aa_mod = $_POST['aa_mod'] <= 0 ? date('Y') : $_POST['aa_mod'];
            $mm_mod = $_POST['mm_mod'] <= 0 ? date('n') : $_POST['mm_mod'];
            $jj_mod = $_POST['jj_mod'] > 31 ? 31 : $_POST['jj_mod'];
            $jj_mod = $jj_mod <= 0 ? date('j') : $jj_mod;
            $hh_mod = $_POST['hh_mod'] > 23 ? $_POST['hh_mod'] -24 : $_POST['hh_mod'];
            $mn_mod = $_POST['mn_mod'] > 59 ? $_POST['mn_mod'] -60 : $_POST['mn_mod'];
            $ss_mod = $_POST['ss_mod'] > 59 ? $_POST['ss_mod'] -60 : $_POST['ss_mod'];
            $modified_date = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $aa_mod, $mm_mod, $jj_mod, $hh_mod, $mn_mod, $ss_mod );
            if ( ! wp_checkdate( $mm_mod, $jj_mod, $aa_mod, $modified_date ) ) {
                unset( $data['post_modified'] );
                unset( $data['post_modified_gmt'] );
                return $data;
            }
            $data['post_modified'] = $modified_date;
            $data['post_modified_gmt'] = get_gmt_from_date( $modified_date );
        }

        return $data;
    }
    add_filter( 'wp_insert_post_data', 'my_insert_post_data', 10, 2 );
    endif;