本文整理汇总了PHP中wc_get_attribute_taxonomy_names函数的典型用法代码示例。如果您正苦于以下问题:PHP wc_get_attribute_taxonomy_names函数的具体用法?PHP wc_get_attribute_taxonomy_names怎么用?PHP wc_get_attribute_taxonomy_names使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wc_get_attribute_taxonomy_names函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: color_layered_nav_init
public function color_layered_nav_init()
{
if (!is_active_widget(false, false, 'woocommerce_layered_nav', true) && !is_admin()) {
global $_chosen_attributes;
$_chosen_attributes = array();
$attribute_taxonomies = wc_get_attribute_taxonomies();
if ($attribute_taxonomies) {
foreach ($attribute_taxonomies as $tax) {
if ($tax->attribute_name == "color") {
$attribute = wc_sanitize_taxonomy_name($tax->attribute_name);
$taxonomy = wc_attribute_taxonomy_name($attribute);
$name = 'filter_' . $attribute;
$query_type_name = 'query_type_' . $attribute;
$taxonomy_exists = in_array($taxonomy, wc_get_attribute_taxonomy_names());
if (!empty($_GET[$name]) && $taxonomy_exists) {
$_chosen_attributes[$taxonomy]['terms'] = explode(',', $_GET[$name]);
if (empty($_GET[$query_type_name]) || !in_array(strtolower($_GET[$query_type_name]), array('and', 'or'))) {
$_chosen_attributes[$taxonomy]['query_type'] = apply_filters('woocommerce_layered_nav_default_query_type', 'and');
} else {
$_chosen_attributes[$taxonomy]['query_type'] = strtolower($_GET[$query_type_name]);
}
}
}
}
}
$wc_query = new WC_Query();
add_filter('loop_shop_post_in', array($wc_query, 'layered_nav_query'));
}
}
示例2: init_trigger
protected function init_trigger()
{
if ($this->woo_ready == false) {
return;
}
global $woocommerce, $_wd_msg;
$_color = 'color';
$attribute_name = isset($_color) ? woocommerce_sanitize_taxonomy_name(stripslashes((string) $_color)) : '';
$attribute_name = wc_attribute_taxonomy_name($attribute_name);
$attribute_name_array = wc_get_attribute_taxonomy_names();
//$taxonomy_exists = taxonomy_exists( wc_attribute_taxonomy_name( $attribute_name ) );
$taxonomy_exists = in_array($attribute_name, $attribute_name_array);
/**************** Check if attribute available ****************/
$this->tax_slug = '';
if (!$taxonomy_exists) {
$this->color_ready = false;
$_wd_msg = "<strong>Color attribute is not exist.</strong>.Go to Products => Attributes,create new attibute with slug <strong>color</strong>";
add_action('admin_notices', array($this, 'show_msg'));
} else {
$this->color_ready = true;
add_image_size('wd_pc_thumb', 30, 30, true);
$_tax_slug = wc_attribute_taxonomy_name($attribute_name);
$this->tax_slug = $_tax_slug;
$this->init_script();
$this->init_handle();
}
}
示例3: constant
function constant()
{
$this->attr_slug = '';
$attribute_name = wc_attribute_taxonomy_name($this->term_slug);
$attribute_name_array = wc_get_attribute_taxonomy_names();
$taxonomy_exists = in_array($attribute_name, $attribute_name_array);
if ($taxonomy_exists) {
$this->attr_slug = $attribute_name;
add_image_size('ts_prod_color_thumb', 30, 30, true);
$this->init_handle();
add_action('admin_enqueue_scripts', array($this, 'register_admin_scripts'));
}
}
示例4: __construct
public function __construct()
{
if (function_exists('wc_get_attribute_taxonomy_names')) {
$attributes = wc_get_attribute_taxonomy_names();
foreach ($attributes as $attribute) {
add_action($attribute . '_add_form_fields', array($this, 'add_image_uploader_to_add_form'), 10, 2);
add_action($attribute . '_edit_form_fields', array($this, 'add_image_uploader_to_edit_form'), 10, 1);
add_action('edited_' . $attribute, array($this, 'save_taxonomy_custom_meta'), 10, 2);
add_action('create_' . $attribute, array($this, 'save_taxonomy_custom_meta'), 10, 2);
add_action('delete_' . $attribute, array($this, 'delete_taxonomy_custom_meta'), 10, 2);
add_action('admin_footer-edit-tags.php', array($this, 'add_fpd_params_modal'));
}
}
}
示例5: __construct
public function __construct()
{
$attributes = wc_get_attribute_taxonomy_names();
// print_r($attributes);
foreach ($attributes as $attribute) {
add_action($attribute . '_add_form_fields', array(&$this, 'add_attr_type_to_add_form'), 10, 2);
add_action($attribute . '_edit_form_fields', array(&$this, 'add_image_uploader_to_edit_form'), 10, 1);
add_action('edited_' . $attribute, array(&$this, 'save_taxonomy_custom_meta'), 10, 2);
add_action('create_' . $attribute, array(&$this, 'save_taxonomy_custom_meta'), 10, 2);
add_action('delete_' . $attribute, array(&$this, 'delete_taxonomy_custom_meta'), 10, 2);
add_filter('manage_edit-' . $attribute . '_columns', array(&$this, 'woocommerce_product_attribute_columns'));
add_filter('manage_' . $attribute . '_custom_column', array(&$this, 'woocommerce_product_attribute_column'), 10, 3);
}
}
示例6: __construct
public function __construct()
{
add_filter('product_attributes_type_selector', array(&$this, 'product_attributes_type_selector'), 20);
$attributes = function_exists('wc_get_attribute_taxonomy_names') ? wc_get_attribute_taxonomy_names() : array();
if (!empty($attributes)) {
foreach ($attributes as $attribute) {
add_action($attribute . '_add_form_fields', array(&$this, 'add_attr_type_to_add_form'), 10, 2);
add_action($attribute . '_edit_form_fields', array(&$this, 'add_image_uploader_to_edit_form'), 10, 1);
add_action('edited_' . $attribute, array(&$this, 'save_taxonomy_custom_meta'), 10, 2);
add_action('create_' . $attribute, array(&$this, 'save_taxonomy_custom_meta'), 10, 2);
add_action('delete_' . $attribute, array(&$this, 'delete_taxonomy_custom_meta'), 10, 2);
add_filter('manage_edit-' . $attribute . '_columns', array(&$this, 'woocommerce_product_attribute_columns'));
add_filter('manage_' . $attribute . '_custom_column', array(&$this, 'woocommerce_product_attribute_column'), 10, 3);
}
}
}
示例7: enqueue_styles_scripts
public function enqueue_styles_scripts($hook)
{
global $post;
$wc_settings_page = 'wc-settings';
//woocommerce settings
if ($hook == 'woocommerce_page_' . $wc_settings_page . '') {
wp_enqueue_style('mspc-admin', plugins_url('/css/admin.css', __FILE__));
wp_enqueue_script('mspc-admin', plugins_url('/js/admin.js', __FILE__), false, Multistep_Product_Configurator::VERSION);
}
//woocommerce post types
if ($hook == 'post-new.php' || $hook == 'post.php') {
//product
if ('product' === $post->post_type) {
wp_enqueue_style('mspc-admin', plugins_url('/css/admin.css', __FILE__));
wp_enqueue_script('mspc-meta-box', plugins_url('/js/meta-box.js', __FILE__), false, Multistep_Product_Configurator::VERSION);
}
}
//add attribute form
if (isset($_GET['page']) && $_GET['page'] == 'product_attributes') {
wp_enqueue_media();
wp_enqueue_style('mspc-admin', plugins_url('/css/admin.css', __FILE__));
wp_enqueue_script('mspc-admin', plugins_url('/js/admin.js', __FILE__), false, Multistep_Product_Configurator::VERSION);
wp_enqueue_style('fpd-admin-icon-font');
wp_enqueue_style('radykal-admin');
wp_enqueue_style('fpd-admin');
wp_enqueue_script('fpd-admin');
}
//edit attribute form
if ($hook == 'edit-tags.php') {
$attributes = wc_get_attribute_taxonomy_names();
if (!empty($attributes) && in_array($_GET['taxonomy'], $attributes)) {
wp_enqueue_media();
wp_enqueue_style('mspc-admin', plugins_url('/css/admin.css', __FILE__));
wp_enqueue_script('mspc-admin', plugins_url('/js/admin.js', __FILE__), false, Multistep_Product_Configurator::VERSION);
wp_enqueue_style('fpd-admin-icon-font');
wp_enqueue_style('radykal-admin');
wp_enqueue_style('fpd-admin');
wp_enqueue_script('fpd-admin');
}
}
}
示例8: query_args
/**
* Query args.
*
* @param array $args
* @param WP_REST_Request $request
* @return array
*/
public function query_args($args, $request)
{
// Set post_status.
$args['post_status'] = $request['status'];
// Taxonomy query to filter products by type, category,
// tag, shipping class, and attribute.
$tax_query = array();
// Map between taxonomy name and arg's key.
$taxonomies = array('product_type' => 'type', 'product_cat' => 'category', 'product_tag' => 'tag', 'product_shipping_class' => 'shipping_class');
// Set tax_query for each passed arg.
foreach ($taxonomies as $taxonomy => $key) {
if (!empty($request[$key])) {
$terms = explode(',', $request[$key]);
$tax_query[] = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $terms);
}
}
// Filter by attribute and term.
if (!empty($request['attribute']) && !empty($request['attribute_term'])) {
if (in_array($request['attribute'], wc_get_attribute_taxonomy_names())) {
$terms = explode(',', $request['attribute_term']);
$tax_query[] = array('taxonomy' => $request['attribute'], 'field' => 'term_id', 'terms' => $terms);
}
}
if (!empty($tax_query)) {
$args['tax_query'] = $tax_query;
}
// Filter by sku.
if (!empty($request['sku'])) {
if (!empty($args['meta_query'])) {
$args['meta_query'] = array();
}
$args['meta_query'][] = array('key' => '_sku', 'value' => $request['sku'], 'compare' => '=');
$args['post_type'] = array('product', 'product_variation');
}
return $args;
}
示例9: query_products
/**
* Helper method to get product post objects
*
* @since 2.1
* @param array $args request arguments for filtering query
* @return WP_Query
*/
private function query_products($args)
{
// Set base query arguments
$query_args = array('fields' => 'ids', 'post_type' => 'product', 'post_status' => 'publish', 'meta_query' => array());
// Taxonomy query to filter products by type, category, tag, shipping class, and
// attribute.
$tax_query = array();
// Map between taxonomy name and arg's key.
$taxonomies_arg_map = array('product_type' => 'type', 'product_cat' => 'category', 'product_tag' => 'tag', 'product_shipping_class' => 'shipping_class');
// Add attribute taxonomy names into the map.
foreach (wc_get_attribute_taxonomy_names() as $attribute_name) {
$taxonomies_arg_map[$attribute_name] = $attribute_name;
}
// Set tax_query for each passed arg.
foreach ($taxonomies_arg_map as $tax_name => $arg) {
if (!empty($args[$arg])) {
$terms = explode(',', $args[$arg]);
$tax_query[] = array('taxonomy' => $tax_name, 'field' => 'slug', 'terms' => $terms);
unset($args[$arg]);
}
}
if (!empty($tax_query)) {
$query_args['tax_query'] = $tax_query;
}
// Filter by specific sku
if (!empty($args['sku'])) {
if (!is_array($query_args['meta_query'])) {
$query_args['meta_query'] = array();
}
$query_args['meta_query'][] = array('key' => '_sku', 'value' => $args['sku'], 'compare' => '=');
$query_args['post_type'] = array('product', 'product_variation');
}
$query_args = $this->merge_query_args($query_args, $args);
return new WP_Query($query_args);
}
示例10: getAttributeTaxonomies
static function getAttributeTaxonomies()
{
global $woocommerce;
if (function_exists('wc_get_attribute_taxonomy_names')) {
$attribute_taxonomies = wc_get_attribute_taxonomy_names();
// WC2.2+
} else {
$attribute_taxonomies = $woocommerce->get_attribute_taxonomy_names();
// legacy support for WC2.0
}
// print_r($attribute_taxonomies);
$attributes = array();
foreach ($attribute_taxonomies as $taxonomy_name) {
$attrib = new stdClass();
// US Shoe Size (Men's) => US Shoe Size (Men's)
// $attrib->name = html_entity_decode( self::getAttributeLabel( $taxonomy_name ), ENT_QUOTES, 'UTF-8' );
$attrib->name = $taxonomy_name;
$attrib->label = html_entity_decode(self::getAttributeLabel($taxonomy_name), ENT_QUOTES, 'UTF-8');
$attributes[] = $attrib;
}
// print_r($attributes);die();
// WPLA()->logger->info( 'getAttributeTaxonomies() result: '.print_r($attributes,1));
return $attributes;
}
示例11: get_attribute_taxonomy_names
/**
* @deprecated 2.1.0
* @return array
*/
public function get_attribute_taxonomy_names()
{
_deprecated_function('Woocommerce->get_attribute_taxonomy_names', '2.1', 'wc_get_attribute_taxonomy_names');
return wc_get_attribute_taxonomy_names();
}
示例12: query_args
/**
* Query args.
*
* @param array $args Request args.
* @param WP_REST_Request $request Request data.
* @return array
*/
public function query_args($args, $request)
{
// Set post_status.
$args['post_status'] = $request['status'];
// Taxonomy query to filter products by type, category,
// tag, shipping class, and attribute.
$tax_query = array();
// Map between taxonomy name and arg's key.
$taxonomies = array('product_cat' => 'category', 'product_tag' => 'tag', 'product_shipping_class' => 'shipping_class');
// Set tax_query for each passed arg.
foreach ($taxonomies as $taxonomy => $key) {
if (!empty($request[$key])) {
$tax_query[] = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $request[$key]);
}
}
// Filter product type by slug.
if (!empty($request['type'])) {
$tax_query[] = array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $request['type']);
}
// Filter by attribute and term.
if (!empty($request['attribute']) && !empty($request['attribute_term'])) {
if (in_array($request['attribute'], wc_get_attribute_taxonomy_names(), true)) {
$tax_query[] = array('taxonomy' => $request['attribute'], 'field' => 'term_id', 'terms' => $request['attribute_term']);
}
}
if (!empty($tax_query)) {
$args['tax_query'] = $tax_query;
}
// Filter featured.
if (is_bool($request['featured'])) {
$args['tax_query'][] = array('taxonomy' => 'product_visibility', 'field' => 'name', 'terms' => 'featured');
}
// Filter by sku.
if (!empty($request['sku'])) {
$args['meta_query'] = $this->add_meta_query($args, array('key' => '_sku', 'value' => $request['sku']));
}
// Filter by tax class.
if (!empty($request['tax_class'])) {
$args['meta_query'] = $this->add_meta_query($args, array('key' => '_tax_class', 'value' => 'standard' !== $request['tax_class'] ? $request['tax_class'] : ''));
}
// Price filter.
if (!empty($request['min_price']) || !empty($request['max_price'])) {
$args['meta_query'] = $this->add_meta_query($args, wc_get_min_max_price_meta_query($request));
}
// Filter product in stock or out of stock.
if (is_bool($request['in_stock'])) {
$args['meta_query'] = $this->add_meta_query($args, array('key' => '_stock_status', 'value' => true === $request['in_stock'] ? 'instock' : 'outofstock'));
}
// Filter by on sale products.
if (is_bool($request['on_sale'])) {
$on_sale_key = $request['on_sale'] ? 'post__in' : 'post__not_in';
$args[$on_sale_key] += wc_get_product_ids_on_sale();
}
// Apply all WP_Query filters again.
if (is_array($request['filter'])) {
$args = array_merge($args, $request['filter']);
unset($args['filter']);
}
// Force the post_type argument, since it's not a user input variable.
if (!empty($request['sku'])) {
$args['post_type'] = array('product', 'product_variation');
} else {
$args['post_type'] = $this->post_type;
}
return $args;
}
示例13: getNames
/**
* @{inheritdoc}
*/
public static function getNames()
{
return wc_get_attribute_taxonomy_names();
}
示例14: query_args
/**
* Query args.
*
* @param array $args
* @param WP_REST_Request $request
* @return array
*/
public function query_args($args, $request)
{
// Set post_status.
$args['post_status'] = $request['status'];
// Taxonomy query to filter products by type, category,
// tag, shipping class, and attribute.
$tax_query = array();
// Map between taxonomy name and arg's key.
$taxonomies = array('product_cat' => 'category', 'product_tag' => 'tag', 'product_shipping_class' => 'shipping_class');
// Set tax_query for each passed arg.
foreach ($taxonomies as $taxonomy => $key) {
if (!empty($request[$key])) {
$terms = explode(',', $request[$key]);
$tax_query[] = array('taxonomy' => $taxonomy, 'field' => 'term_id', 'terms' => $terms);
}
}
// Filter product type by slug.
if (!empty($request['type'])) {
$terms = explode(',', $request['type']);
$tax_query[] = array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => $terms);
}
// Filter by attribute and term.
if (!empty($request['attribute']) && !empty($request['attribute_term'])) {
if (in_array($request['attribute'], wc_get_attribute_taxonomy_names())) {
$terms = explode(',', $request['attribute_term']);
$tax_query[] = array('taxonomy' => $request['attribute'], 'field' => 'term_id', 'terms' => $terms);
}
}
if (!empty($tax_query)) {
$args['tax_query'] = $tax_query;
}
// Filter by sku.
if (!empty($request['sku'])) {
if (!empty($args['meta_query'])) {
$args['meta_query'] = array();
}
$args['meta_query'][] = array('key' => '_sku', 'value' => $request['sku'], 'compare' => '=');
}
// Apply all WP_Query filters again.
if (is_array($request['filter'])) {
$args = array_merge($args, $request['filter']);
unset($args['filter']);
}
// Force the post_type argument, since it's not a user input variable.
if (!empty($request['sku'])) {
$args['post_type'] = $this->get_post_types();
} else {
$args['post_type'] = $this->post_type;
}
return $args;
}
示例15: save_attribute_fields
/**
* save_attribute_fields function.
*
* @param mixed $term_id Term ID being saved
* @param mixed $tt_id
* @param string $taxonomy
*/
public function save_attribute_fields($term_id, $tt_id = '', $taxonomy = '')
{
$taxonomy_names = wc_get_attribute_taxonomy_names();
if (isset($_POST['display_type']) && in_array($taxonomy, $taxonomy_names)) {
update_woocommerce_term_meta($term_id, 'display_type', esc_attr($_POST['display_type']));
}
if (isset($_POST['term_color']) && in_array($taxonomy, $taxonomy_names)) {
update_woocommerce_term_meta($term_id, 'term_color', esc_attr($_POST['term_color']));
}
if (isset($_POST['attribute_thumbnail_id']) && in_array($taxonomy, $taxonomy_names)) {
update_woocommerce_term_meta($term_id, 'thumbnail_id', absint($_POST['attribute_thumbnail_id']));
}
}