Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/24hwww/wc-hide-products-by-term
Hide products by term or attribute in woocommerce
https://github.com/24hwww/wc-hide-products-by-term
Last synced: about 15 hours ago
JSON representation
Hide products by term or attribute in woocommerce
- Host: GitHub
- URL: https://github.com/24hwww/wc-hide-products-by-term
- Owner: 24hwww
- Created: 2024-07-27T18:03:02.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-27T18:04:43.000Z (6 months ago)
- Last Synced: 2024-11-11T06:36:12.623Z (about 2 months ago)
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hide products by term or attribute in WooCommerce
Hide products by term or attribute in woocommerce
```php
if (!class_exists('hidden_products_taxonomy_by_term')) {
class hidden_products_taxonomy_by_term{
private static $_instance = null;
public static function instance() {
return is_null( self::$_instance ) ? self::$_instance = new self() : self::$_instance;
}
public function __construct() {
}
public function get_all_taxonomies_woocommerce(){
$output = [];
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
$output = array_keys(get_taxonomies(['object_type' => array( 'product' )], 'names' ));
}
return $output;
}
public static function init() {
$instance = self::instance();
$taxonomies = $instance->get_all_taxonomies_woocommerce();
if(is_array($taxonomies) && count($taxonomies) > 0){
foreach($taxonomies as $taxonomy){
add_action( "{$taxonomy}_edit_form_fields", [$instance,'add_field_hidden_or_not_func'], 10, 2 );
add_action( "{$taxonomy}_add_form_fields", [$instance,'add_field_hidden_or_not_func'], 10, 2 );
}
add_action( 'woocommerce_after_add_attribute_fields', [$instance,'add_field_hidden_or_not_func'], 10, 2 );
add_action( 'woocommerce_after_edit_attribute_fields', [$instance,'add_field_hidden_or_not_func'], 10, 2 );
add_action( 'woocommerce_attribute_added', [$instance,'save_custom_field_wc_attribute_func'], 10, 2 );
add_action( 'woocommerce_attribute_updated', [$instance,'save_custom_field_wc_attribute_func'], 10, 2 );
}
add_shortcode( 'debug_plugin_dev', [$instance,'debug_plugin_dev_func'] );
}
public function add_field_hidden_or_not_func($term='', $taxonomy=''){
$term_id = !empty($term->term_id) ? $term->term_id : '';
$check_field = get_term_meta($term_id, 'hidden_products_taxonomy_by_term', true );
?>
Ocultar productos que tengan este termino o atributo.
Ocultar productos que tengan este termino o atributo.
get_all_taxonomies_woocommerce());
}
}
add_action( 'admin_init', ['hidden_products_taxonomy_by_term', 'init']);
}
```