2016-05-31 6 views
1

woocommerceの手動管理注文ページにメタボックスを追加したいと思います。woocommerceのmeta_boxオプションをshop_orderの管理注文

このメタボックスはその後、私は、フォームの場合その管理者を必要とする選択がアクション をトリガーする場合は、これまで私が読んだものから、それはこの

function add_meta_boxes() 
{ 
add_meta_box( 
    'Meta Box', // ID, should be a string. 
    'woocommerce-action-trigger', // Meta Box Title. 
    'my_meta_box', // Your call back function, this is where your form field will go. 
    'shop_order', // The post type you want this to show up on, can be post, page, or custom post type. 
    'side', // The placement of your meta box, can be normal or side. 
    'default' // The priority in which this will be displayed. 
); 
} 

のようなものを起動する必要がありますことを、チェックボックスが必要になりますあなたは私がチェックボックスにのみ、この順序のためwoocommerceで何かを外したいので、それだけでこのセッションのために、このページで行われ、この時点で見ることができるように選択するには、アクション

function triggeraction_meta_box() { 
$checkboxMeta = make_action_happen(); 
} 

    <input type="checkbox" name="action" id="action" value="yes" <?php if (isset ($checkboxMeta['action'])) checked($checkboxMeta['action'][0], 'yes'); ?> />make_action_happen<br /> 

をトリガします。

私のコーディングは非常に非常に非常に基本的です。

答えて

0
function wporg_add_custom_box() { 
    $screens = ['shop_order', 'wporg_cpt']; 
    foreach ($screens as $screen) { 
     add_meta_box(
      'wporg_box_id',   // Unique ID 
      'Custom Meta Box Title', // Box title 
      'wporg_custom_box_html', // Content callback, must be of type callable 
      $screen     // Post type 
     ); 
    } 
} 
add_action('add_meta_boxes', 'wporg_add_custom_box'); 



function wporg_custom_box_html($post) 
{ 
    $value = get_post_meta($post->ID, '_wporg_meta_key', true); 
    ?> 
    <label for="wporg_field">Description for this field</label> 
    <select name="wporg_field" id="wporg_field" class="postbox"> 
     <option value="">Select something...</option> 
     <option value="something" <?php selected($value, 'something'); ?>>Something</option> 
     <option value="else" <?php selected($value, 'else'); ?>>Else</option> 
    </select> 
    <?php 
} 

function wporg_save_postdata($post_id) { 
    if (array_key_exists('wporg_field', $_POST)) { 
     update_post_meta(
      $post_id, 
      '_wporg_meta_key', 
      $_POST['wporg_field'] 
     ); 
    } 
} 
add_action('save_post', 'wporg_save_postdata'); 
関連する問題