Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once dirname( __FILE__ ) . '/quote_print.php';
- function p52_quote_post_type() {
- register_post_type( 'p52-quote',
- array(
- 'labels' => array(
- 'name' => _x('Quote', 'post type general name'),
- 'singular_name' => _x('Quote', 'post type singular name'),
- 'add_new' => _x('Add New', 'quote'),
- 'add_new_item' => __('Add New Quote'),
- 'edit_item' => __('Edit Quote'),
- 'new_item' => __('New Quote'),
- 'all_items' => __('All Quotes'),
- 'view_item' => __('View Quote'),
- 'search_items' => __('Search Quotes'),
- 'not_found' => __('Quote wasn\'t found'),
- 'not_found_in_trash' => __('Quote wasn\'t found in Trash'),
- 'parent_item_colon' => '',
- 'menu_name' => 'P52 Quotes'
- ),
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'supports' => array( 'title' ),
- 'capability_type' => 'post',
- 'rewrite' => true,
- 'menu_position' => 5,
- 'hierarchical' => false,
- 'menu_icon' => 'dashicons-admin-links',
- )
- );
- }
- add_action( 'init', 'p52_quote_post_type' );
- /***************************
- * create contact metaboxes
- ***************************/
- function p52_register_quote_contact_meta_boxes( $meta_boxes ) {
- $prefix = 'p52_quote_';
- // Get all customer custom post type posts
- $customers = get_posts( array(
- 'posts_per_page' => -1,
- 'post_type' => 'p52-contact'
- ) );
- // start customer
- $meta_boxes[] = array(
- 'id' => $prefix . 'customer',
- 'title' => 'Customer Info',
- 'pages' => 'p52-quote',
- 'context' => 'normal',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'name' => 'Name',
- 'id' => $prefix . 'name',
- 'type' => 'post',
- 'post_type' => 'p52-contact',
- 'placeholder' => 'Select a Customer',
- 'columns' => 6
- ),
- array(
- 'name' => 'Company',
- 'id' => $prefix . 'company',
- 'type' => 'text',
- 'columns' => 6
- ),
- array(
- 'name' => 'Email',
- 'id' => $prefix . 'email',
- 'type' => 'text',
- 'columns' => 6
- ),
- array(
- 'name' => 'Phone',
- 'id' => $prefix . 'phone',
- 'type' => 'hidden',
- 'columns' => 6
- ),
- array(
- 'name' => 'Address',
- 'id' => $prefix . 'address',
- 'type' => 'textarea',
- 'columns' => 6
- ),
- array(
- 'name' => 'Delivery Address',
- 'id' => $prefix . 'delivery_address',
- 'type' => 'textarea',
- 'columns' => 6
- ),
- ), // end customer fields
- ); // end customer
- // Append phone or another field of customer to meta box above.
- foreach ( $customers as $customer )
- {
- // Show this phone field if match name.
- $meta_box['fields'][] = array(
- 'name' => 'Phone',
- 'id' => $prefix . 'phone_' . $customer->ID,
- 'type' => 'text',
- 'std' => get_post_meta( $customer->ID, 'p52_quote_phone', true ),
- 'visible' => array( $prefix . 'name', $customer->ID )
- );
- }
- $meta_boxes[] = $meta_box;
- return $meta_boxes;
- }
- add_filter( 'rwmb_meta_boxes', 'p52_register_quote_contact_meta_boxes' );
- // Save data to phone field
- add_action('rwmb_before_save_post', function($post_id)
- {
- // Get person ID to save from "Select a Customer" field
- $person_to_save = intval( $_POST['p52_quote_name'] );
- // Save related field to phone field
- $_POST['p52_quote_phone'] = $_POST['p52_quote_phone_' . $person_to_save];
- // Unset all hidden fields
- foreach ( $_POST as $key => $value )
- {
- if ( strpos( $key, 'p52_quote_phone_' ) )
- unset( $_POST[$key] );
- }
- } );
- /***************************
- * create product metaboxes
- ***************************/
- function p52_register_quote_product_meta_boxes( $meta_boxes ) {
- $prefix = 'p52_quote_';
- // start products
- $meta_boxes[] = array(
- 'id' => $prefix . 'products',
- 'title' => 'Product Info',
- 'pages' => 'p52-quote',
- 'context' => 'normal',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'id' => 'quote-products',
- //'name' => 'Products',
- 'type' => 'Group',
- 'clone' => true,
- 'columns' => 12,
- 'fields' => array(
- array(
- 'name' => 'Product',
- 'id' => $prefix . 'product',
- 'type' => 'post',
- 'post_type' => 'p52-product',
- 'placeholder' => 'Select a Product',
- 'columns' => 4
- ),
- array(
- 'name' => 'Description',
- 'id' => $prefix . 'description',
- 'type' => 'textarea',
- 'columns' => 4
- ),
- array(
- 'name' => 'Qty',
- 'id' => $prefix . 'qty',
- 'type' => 'number',
- 'step' => .01,
- 'columns' => 2
- ),
- array(
- 'name' => 'Price',
- 'id' => $prefix . 'price',
- 'type' => 'number',
- 'step' => .01,
- 'columns' => 2
- ),
- ), // end product fields
- ), // end group fieds
- ), // end all fields
- ); // end products
- return $meta_boxes;
- }
- add_filter( 'rwmb_meta_boxes', 'p52_register_quote_product_meta_boxes' );
- /***************************
- * create contact metaboxes
- ***************************/
- function p52_register_quote_notes_meta_boxes( $meta_boxes ) {
- $prefix = 'p52_quote_';
- // start notes
- $meta_boxes[] = array(
- 'id' => $prefix . 'quote_notes',
- 'title' => 'Notes',
- 'pages' => 'p52-quote',
- 'context' => 'normal',
- 'priority' => 'low',
- 'fields' => array(
- array(
- 'name' => 'Notes',
- 'id' => $prefix . 'notes',
- 'std' => 'Quote valid for 30 days from date of issue',
- 'type' => 'textarea',
- 'columns' => 12,
- ),
- ), // end your fields
- ); // end your info
- return $meta_boxes;
- }
- add_filter( 'rwmb_meta_boxes', 'p52_register_quote_notes_meta_boxes' );
- function build_table($products){
- $yourcurrency = quote_currency_info();
- // data rows
- foreach( $products as $key=>$value){
- $html .= '<tr class="item-row">';
- $html .= '<td>' . get_the_title($value[p52_quote_product]) . '</td>';
- $html .= '<td>' . $value[p52_quote_description] . '</td>';
- $html .= '<td>' . $value[p52_quote_qty] . '</td>';
- $html .= '<td>' . $yourcurrency . ' ' . $value[p52_quote_price] . '</td>';
- $html .= '<td>' . $yourcurrency . ' ' . $value[p52_quote_qty] * $value[p52_quote_price] . '</td>';
- $html .= '</tr>';
- }
- return $html;
- }
- function get_price_total($products){
- $total=0;
- foreach( $products as $key=>$value){
- $total+=$value[p52_quote_qty] * $value[p52_quote_price];
- }
- return $total;
- }`
- And this is the full code for my contact
- `<?php
- /***************************
- * create contact cpt
- ***************************/
- function p52_contact_post_type() {
- register_post_type( 'p52-contact',
- array(
- 'labels' => array(
- 'name' => _x('Contact', 'post type general name'),
- 'singular_name' => _x('Contact', 'post type singular name'),
- 'add_new' => _x('Add New', 'Contact'),
- 'add_new_item' => __('Add New Contact'),
- 'edit_item' => __('Edit Contact'),
- 'new_item' => __('New Contact'),
- 'all_items' => __('All Contacts'),
- 'view_item' => __('View Contacts'),
- 'search_items' => __('Search Contacts'),
- 'not_found' => __('Contact wasn\'t found'),
- 'not_found_in_trash' => __('Contact wasn\'t found in Trash'),
- 'parent_item_colon' => '',
- 'menu_name' => 'P52 Contacts'
- ),
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'supports' => array( 'title' ),
- 'capability_type' => 'post',
- 'rewrite' => true,
- 'menu_position' => 5,
- 'hierarchical' => false,
- 'menu_icon' => 'dashicons-admin-users',
- )
- );
- }
- add_action( 'init', 'p52_contact_post_type' );
- /***************************
- * create contact metaboxes
- ***************************/
- function p52_contact_before_meta_boxes( $meta_boxes ) {
- $prefix = 'p52_contact_';
- // contact info meta box
- $meta_boxes[] = array(
- 'id' => $prefix . 'contact',
- 'title' => 'Contact Info',
- 'pages' => array('p52-contact'),
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'name' => 'Company',
- 'id' => $prefix . 'company',
- 'type' => 'text',
- 'columns' => 6
- ),
- array(
- 'name' => 'Relationship',
- 'id' => $prefix . 'relationship',
- 'type' => 'select',
- 'options' => array(
- 'prospect' => 'Prospect',
- 'lead' => 'Lead',
- 'client' => 'Client',
- 'model' => 'Model',
- 'assitant' => 'Assistant',
- 'supplier' => 'Supplier'
- ),
- 'placeholder' => 'Choose your relationship',
- 'columns' => 6
- ),
- array(
- 'name' => 'Phone',
- 'id' => $prefix . 'phone',
- 'type' => 'text',
- 'columns' => 6
- ),
- array(
- 'name' => 'Email',
- 'id' => $prefix . 'email',
- 'type' => 'text',
- 'columns' => 6
- ),
- array(
- 'name' => 'Address',
- 'id' => $prefix . 'address',
- 'type' => 'textarea',
- 'columns' => 6
- ),
- array(
- 'name' => 'Postal Address',
- 'id' => $prefix . 'postal',
- 'type' => 'textarea',
- 'columns' => 6
- ),
- )
- );
- // contact tasks meta box
- $meta_boxes[] = array(
- 'id' => $prefix . 'tasks',
- 'title' => 'Tasks',
- 'pages' => array('p52-contact'),
- 'context' => 'normal',
- 'priority' => 'high',
- 'fields' => array(
- array(
- 'id' => $prefix . 'contact_tasks',
- 'type' => 'group',
- 'clone' => true,
- 'fields' => array(
- array(
- 'name' => 'Task Name',
- 'id' => $prefix . 'task_name',
- 'type' => 'text',
- 'columns' => 6
- ),
- array(
- 'name' => 'Task Style',
- 'id' => $prefix . 'task_style',
- 'type' => 'select',
- 'options' => array(
- 'task_email' => 'Email',
- 'task_phone' => 'Phone',
- 'task_meeting' => 'Meeting',
- 'task_skype' => 'Skype',
- 'task_mockup' => 'Mockup',
- 'task_wireframe' => 'Wireframe',
- 'task_design' => 'Design',
- 'task_photography' => 'Photography',
- 'task_production' => 'Production',
- ),
- 'placeholder' => 'Select a style',
- 'columns' => 6
- ),
- array(
- 'name' => 'Due Date',
- 'id' => $prefix . 'task_due',
- 'type' => 'datetime',
- 'columns' => 4
- ),
- array(
- 'name' => 'Status',
- 'id' => $prefix . 'task_status',
- 'type' => 'select',
- 'options' => array(
- 'task_not-started' => 'Not Started',
- 'task_in_progress' => 'In Progess',
- 'task_waiting_customer' => 'Waiting Customer',
- 'task_completed' => 'Completed',
- ),
- 'placeholder' => 'Select a status',
- 'columns' => 4
- ),
- array(
- 'name' => 'Date Complete',
- 'id' => $prefix . 'task_date_completed',
- 'type' => 'datetime',
- 'columns' => 4
- ),
- array(
- 'name' => 'Task Description',
- 'id' => $prefix . 'task_description',
- 'type' => 'wysiwyg',
- ),
- ),// end task fields
- ),
- ),
- ); // end tasks
- // contact social meta box
- $meta_boxes[] = array(
- 'id' => $prefix . 'social',
- 'title' => 'Social Links',
- 'pages' => array('p52-contact'),
- 'context' => 'side',
- 'fields' => array(
- array(
- 'id' => $prefix . 'contact_social',
- 'type' => 'group',
- 'clone' => true,
- 'fields' => array(
- array(
- 'name' => 'Social Media',
- 'id' => $prefix . 'social_type',
- 'type' => 'select',
- 'options' => array(
- 'facebook' => 'Facebook',
- 'twitter' => 'Twitter',
- 'google' => 'Google+',
- 'pinterest' => 'Pinterest',
- 'instagram' => 'Instagram',
- 'linkedin' => 'LinkedIn',
- 'website' => 'Website',
- '500px' => '500px',
- 'behance' => 'Behance',
- ),
- 'placeholder' => 'Select the Social Media type',
- ),
- array(
- 'name' => 'Link',
- 'id' => $prefix . 'social_link',
- 'type' => 'text',
- 'placeholder' => 'Enter the URL',
- ),
- ),// end task fields
- ),
- ),
- ); // end tasks
- return $meta_boxes;
- }
- add_filter( 'rwmb_meta_boxes', 'p52_contact_before_meta_boxes' );`
- And then finally my products
- `<?php
- /***************************
- * create product cpt
- ***************************/
- function p52_product_post_type() {
- register_post_type( 'p52-product',
- array(
- 'labels' => array(
- 'name' => _x('Product', 'post type general name'),
- 'singular_name' => _x('Product', 'post type singular name'),
- 'add_new' => _x('Add New', 'Product'),
- 'add_new_item' => __('Add New Product'),
- 'edit_item' => __('Edit Product'),
- 'new_item' => __('New Product'),
- 'all_items' => __('All Products'),
- 'view_item' => __('View Products'),
- 'search_items' => __('Search Products'),
- 'not_found' => __('Product wasn\'t found'),
- 'not_found_in_trash' => __('Product wasn\'t found in Trash'),
- 'parent_item_colon' => '',
- 'menu_name' => 'P52 Products'
- ),
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
- 'capability_type' => 'post',
- 'rewrite' => true,
- 'menu_position' => 5,
- 'hierarchical' => false,
- 'menu_icon' => 'dashicons-cart',
- )
- );
- }
- add_action( 'init', 'p52_product_post_type' );
- /***************************
- * create product metaboxes
- ***************************/
- function p52_register_product_meta_boxes( $meta_boxes ) {
- $prefix = 'p52_product_';
- // b&a meta box
- $meta_boxes[] = array(
- 'id' => 'product_info',
- 'title' => 'Product Info',
- 'pages' => array('p52-product'),
- 'context' => 'side',
- 'fields' => array(
- array(
- 'name' => 'Cost',
- 'id' => $prefix . 'cost',
- 'type' => 'number',
- ),
- array(
- 'name' => 'RRP',
- 'id' => $prefix . 'rrp',
- 'type' => 'number',
- ),
- array(
- 'name' => 'Unit',
- 'id' => $prefix . 'unit',
- 'type' => 'select',
- 'options' => array(
- 'ea' => 'Each',
- 'hr' => 'Hourly',
- 'day' => 'Daily',
- 'wk' => 'Weekly',
- 'mth' => 'Month',
- 'yr' => 'Yearly'
- ),
- 'placeholder' => 'Select your unit of sale',
- ),
- array(
- 'name' => 'Type',
- 'id' => $prefix . 'type',
- 'type' => 'select',
- 'options' => array(
- 'product' => 'Product',
- 'service' => 'Service',
- 'subscription' => 'Subscription',
- 'support' => 'Support',
- 'license' => 'License',
- ),
- 'placeholder' => 'Select your product type',
- ),
- ),
- );
- return $meta_boxes;
- }
- add_filter( 'rwmb_meta_boxes', 'p52_register_product_meta_boxes' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement