PHP code example of 369work / tokusho-generator

1. Go to this page and download the library: Download 369work/tokusho-generator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

369work / tokusho-generator example snippets


use Tokusho\TokushoGenerator;
use Tokusho\Exception\ValidationException;

$generator = new TokushoGenerator([
    'company_name'      => '山田太郎商店',
    'responsible_name'  => '山田太郎',
    'address'           => '〒150-0001 東京都渋谷区神宮前1-2-3',
    'phone'             => '03-1234-5678',
    'email'             => '[email protected]',
    'price_description' => '各商品ページに記載の価格(税込)',
    'payment_methods'   => 'クレジットカード(Visa / Mastercard)',
    'payment_timing'    => '購入手続き完了時',
    'shipping_fee'      => '送料無料(デジタル納品)',
    'delivery_timing'   => '決済完了後、即時ダウンロード可能',
    'return_policy'     => '商品の性質上、購入後の返品・返金はお断りしています。',
]);

// バリデーション(エラーがあれば例外をスロー)
try {
    $generator->validate();
} catch (ValidationException $e) {
    foreach ($e->getErrors() as $field => $errors) {
        echo "[{$field}] " . implode(', ', $errors) . "\n";
    }
}

// HTMLページ生成
echo $generator->toHTML();

// 配列として取得
$array = $generator->toArray();

// JSONとして取得
$json = $generator->toJSON();

new TokushoGenerator(array $data = [], array $options = [])

use Tokusho\Field\FieldDefinition;

$generator->addField(new FieldDefinition(
    key: 'license_number',
    label: '古物商許可番号',
    

// WordPress プラグイン内での使用例
ugin_render_tokusho_page(): string
{
    $data = get_option('my_plugin_tokusho_data', []);

    $generator = new TokushoGenerator($data, ['standalone' => false]);

    return $generator->toHTML();
}