welcart PHPswitch文で在庫ステータスを表示させる

Filed under: welcart — kdcs @ 19年12月19日 木曜日

welcartでカテゴリー別商品表示(archive-item.phpなど)を行う時に「売り切れ」や「入荷待ち」などの在庫ステータス表示をさせる方法

switch ~ case を使う

<?php
    $status = usces_get_itemZaiko( 'id' );
    switch( $status ){
        case 1:
            echo '<span class="few">残りわずか</span>';
            break;
        case 2:
            echo '<span class="soldout">売り切れ</span>';
            break;
        case 3:
            echo '<span class="waiting">入荷待ち</span>';
            break;
    }
?>

2行目のコードで、在庫ステータスを数値(id)として取得する

0 在庫有り
1 在庫僅少
2 売切れ
3 入荷待ち
4 廃盤

welcart 関連商品表示に関する調査と結果

Filed under: welcart — kdcs @ 19年12月17日 火曜日

welcartのテーマを自作する場合、プラグイン内のwc_templatesフォルダを自作テーマ内にコピーしてカスタマイズする。
usc-e-shop > theme > welcart_default > wc_templates

関連商品の表示に関しては、商品マスターにて個々の商品のタグに関連させたい商品コードをタグとして登録する必要がある。(数が多いと大変なのであまり実用的ではない)

試しにタグ付けして表示させてみるとエラーが出る
Warning: call_user_func_array() expects…

このエラーの解決方法は、welcart_defaultフォルダ内のfunctions.phpから118~148行目あたり「excerpt」とある中の、いくつかのタグを自作テーマのfunctions.phpへコピーすると解決する。

(続きを読む…)

welcart 商品在庫数により数量ステータス表示を変える

Filed under: welcart — kdcs @ 19年12月13日 金曜日

welcartで商品の在庫数により、「在庫あり」「〇点在庫あり」「設定ステータス表示」に変える。
※購入により在庫数が0になるとelseの内容(売り切れ)が表示され、管理画面での在庫状態操作では
「在庫有り」の時は数量表示、それ以外は設定された状態を表示する。

<?php
$stock_rest = usces_the_itemZaikoNum('return');
if( usces_get_itemZaiko('id') <= 1 ){
    if( $stock_rest >= 15 ){ //在庫数が15以上の場合
        echo '在庫有り';
    } elseif ( 0 < $stock_rest && $stock_rest < 15 ){ //在庫数が0より大きく15未満の場合
        echo $stock_rest. '点在庫有り';
    }
} else { //その他の場合
    usces_the_itemZaikoStatus(); //在庫状態を表示
}
?>

welcart テンプレートタグ

Filed under: welcart — kdcs @ 19年12月7日 土曜日

welcartのテンプレートタグ(公式ページより)

(続きを読む…)

welcart 数量入力フィールドの前後に+/-のボタンを設置する

Filed under: JavaScript,welcart — kdcs @ 19年12月6日 金曜日

welcartの商品詳細ページにある商品購入用フォームの数量をプラス+と-ボタンで入力できるようにする。
※jQueryを使用するので先にjQeryが読み込まれている必要あり

2019年12月14日現在 footer.php内に記述

<?php if(is_single()): ?>
<script type="text/javascript">
jQuery(function($){
    $(".skuquantity").after('<input type="button" value="+" id="add1" class="plus" />').before('<input type="button" value="-" id="minus1" class="minus" />');
    $(".plus").click(function(){
        var currentVal = parseInt(jQuery(this).prev(".skuquantity").val());
        if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0;
        $(this).prev(".skuquantity").val(currentVal + 1);
    });
    $(".minus").click(function(){
        var currentVal = parseInt(jQuery(this).next(".skuquantity").val());
        if (currentVal == "NaN") currentVal = 0;
        if (currentVal > 0) {
            $(this).next(".skuquantity").val(currentVal - 1);
        }
    });
});
</script>
<?php endif; ?>

サイト内検索

カテゴリー

最近の投稿

↑上に戻る