81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
|
|
class Wiaas_Product {
|
|
|
|
public static function init() {
|
|
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-category.php';
|
|
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-supplier.php';
|
|
require_once dirname( __FILE__ ) . '/product/class-wiaas-product-quick-edit.php';
|
|
|
|
|
|
add_filter('woocommerce_register_post_type_product', array(__CLASS__, 'manage_product_settings'));
|
|
|
|
add_filter('woocommerce_taxonomy_args_product_tag', array(__CLASS__, 'manage_tags_as_references'));
|
|
}
|
|
|
|
/**
|
|
* Update product type settins before it is created:
|
|
* - Define capabilities for editing products so we can easily control read/edit/create access for them
|
|
* - Declare fields supported by product
|
|
*
|
|
* @param $args
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function manage_product_settings($args) {
|
|
|
|
$args['capabilities'] = array(
|
|
'edit_post' => 'edit_product',
|
|
'read_post' => 'read_product',
|
|
'delete_post' => 'delete_product',
|
|
'edit_posts' => 'edit_products',
|
|
'edit_others_posts' => 'edit_others_products',
|
|
'publish_posts' => 'publish_products',
|
|
'read_private_posts' => 'read_private_products',
|
|
'create_posts' => 'create_products', // use `create_products` instead of default `edit_products`
|
|
);
|
|
|
|
$args['supports'] = array( 'title', 'thumbnail' );
|
|
|
|
|
|
return $args;
|
|
}
|
|
|
|
/**
|
|
* Hide default metabox for product tags
|
|
*
|
|
* @param $args
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function manage_tags_as_references($args) {
|
|
// hide metabox
|
|
$args['meta_box_cb'] = false;
|
|
|
|
// update labels
|
|
$args['labels'] = array(
|
|
'name' => __( 'Product references', 'wiaas' ),
|
|
'singular_name' => __( 'Reference', 'wiaas' ),
|
|
'menu_name' => _x( 'References', 'Admin menu name', 'wiaas' ),
|
|
'search_items' => __( 'Search references', 'wiaas' ),
|
|
'all_items' => __( 'All references', 'wiaas' ),
|
|
'edit_item' => __( 'Edit reference', 'wiaas' ),
|
|
'update_item' => __( 'Update reference', 'wiaas' ),
|
|
'add_new_item' => __( 'Add new reference', 'wiaas' ),
|
|
'new_item_name' => __( 'New reference name', 'wiaas' ),
|
|
'popular_items' => __( 'Popular references', 'wiaas' ),
|
|
'separate_items_with_commas' => __( 'Separate references with commas', 'wiaas' ),
|
|
'add_or_remove_items' => __( 'Add or remove references', 'wiaas' ),
|
|
'choose_from_most_used' => __( 'Choose from the most used references', 'wiaas' ),
|
|
'not_found' => __( 'No references found', 'wiaas' ),
|
|
);
|
|
|
|
return $args;
|
|
}
|
|
|
|
public static function get_supplier_id($product_id){
|
|
return wp_get_post_terms($product_id, 'supplier', array('fields' => 'ids'))[0];
|
|
}
|
|
}
|
|
|
|
Wiaas_Product::init(); |