Skip to content

Instantly share code, notes, and snippets.

@cannap
Last active June 30, 2017 10:37
Show Gist options
  • Save cannap/4120b97be836a8215a5d8ffb9b5b3877 to your computer and use it in GitHub Desktop.
Save cannap/4120b97be836a8215a5d8ffb9b5b3877 to your computer and use it in GitHub Desktop.
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
//require('VariantSettings.php');
/*
* Todo: php max_input_vars and woocommerce
* Todo: define( 'WC_MAX_LINKED_VARIATIONS', 100 );
*/
class VariantImages {
public function __construct() {
add_action( 'admin_init', array( $this, 'init_attribute_hooks' ) );
add_filter( 'product_attributes_type_selector', array(
$this,
'add_attribute_selector'
) );
//woocommerce_atributes for front
add_action( 'woocommerce_product_option_terms', array(
$this,
'add_image_upload_field'
), 10, 2 );
/* add_action( 'woocommerce_dropdown_variation_attribute_options_html', array(
$this,
'display_image_attributes'
) );
*/
$attribute_taxonomies = wc_get_attribute_taxonomies();
foreach ( $attribute_taxonomies as $attr_tax ) {
$tax_name = 'pa_' . $attr_tax->attribute_name;
//WHAT EVER THIS MAKES ITS NOT WORKING
add_action( $tax_name . '_add_form_fields', array( $this, 'add_attribute_term_fields' ) );
add_action( $tax_name . '_edit_form_fields', array( $this, 'add_attribute_term_fields' ) );
/*
*
add_action( $tax_name . '_edit_form_fields', array( $this, 'edit_attribute_term_fields' ), 20, 2 );
*/
}
}
function init_attribute_hooks() {
if ( empty( $attribute_taxonomies ) ) {
return;
}
add_action( 'created_term', array( $this, 'save_term_meta' ), 10, 2 );
add_action( 'edit_term', array( $this, 'save_term_meta' ), 10, 2 );
}
function add_attributes_term_fields() {
/*
$taxonomy = isset( $_GET['taxonomy'] ) ? $_GET['taxonomy'] : false;
if ( ! $taxonomy ) {
return;
}
*/
}
function save_term_meta( $term_id, $tt_id ) {
if ( isset( $_POST['image'] ) ) {
}
}
/**
* Zeigt das HTML in der Produkt Eigeschaft von Images
*
* @param $tax
*/
public function add_image_upload_field( $tax, $i ) {
global $woocommerce;
$attribute_taxonomy_name = 'pa_' . $tax->attribute_name;
//$all_terms = get_terms( $attribute_taxonomy_name );
if ( 'image' === $tax->attribute_type ) {
?>
<select multiple="multiple" data-placeholder="<?php _e( 'Select terms', 'renka-text-domain' ); ?>"
class="multiselect attribute_values" name="attribute_values[<?php echo $i; ?>][]">
<option value="wtf"> wtf</option>
</select>
<button type="button">Add Image</button>
<?php
}
}
/**
* @description Fügt eine neues feld "Images" hinzu um Verschiedene Variationen von Bilder darzustellen
*
* @param $types
*
* @return array
*/
function add_attribute_selector( $types ) {
$image_type = array(
'image' => __( 'Image', 'renka-text-domain' )
);
return array_merge( $types, $image_type );
}
function display_image_attributes() {
$type = 'image';
}
}
new VariantImages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment