I am trying to add affiliate links to the Woocommerce variations. The idea is to have a unique http link/URL(affiliate link) for each product variation. A link/URL that I can enter in the Woocommerce backend and when a customer clicks on the 'Add to cart' button, a new web-page is loaded (based on the corresponding URL of that product)
This can be easily achieved for the products with no variations. But there is no such out of the box functionality for achieving the same thing for the products with variations.
I came across a solution over here
I implemented the code but whenever I try to enter the URL in the backend and try to save my changes, the link disappears, don't know what's going wrong with my code.
// Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
// Save Fields
add_action( 'woocommerce_process_product_meta_variable', 'variable_fields_process', 10, 1 );
function variable_fields( $loop, $variation_data ) {
?>
<tr>
<td>
<div>
<label><?php _e( 'Affiliate URL', 'woocommerce' ); ?></label>
<input type="text" size="5" name="my_affiliate_url[<?php echo $loop; ?>]" value="<?php echo $variation_data['_my_affiliate_url'][0]; ?>"/>
</div>
</td>
</tr>
<?php
}
function variable_fields_js() {
?>
<tr>
<td>
<div>
<label><?php _e( 'My Custom Field', 'woocommerce' ); ?></label>
<input type="text" size="5" name="my_affiliate_url[' + loop + ']" />
</div>
</td>
</tr>
<?php
}
function variable_fields_process( $post_id ) {
if (isset( $_POST['variable_sku'] ) ) :
$variable_sku = $_POST['variable_sku'];
$variable_post_id = $_POST['variable_post_id'];
$variable_custom_field = $_POST['my_affiliate_url'];
for ( $i = 0; $i < sizeof( $variable_sku ); $i++ ) :
$variation_id = (int) $variable_post_id[$i];
if ( isset( $variable_custom_field[$i] ) ) {
update_post_meta( $variation_id, '_my_affiliate_url', stripslashes( $variable_custom_field[$i] ) );
}
endfor;
endif;
}
//front-end variations
function woocommerce_variable_add_to_cart() {
global $product, $post;
$variations = $product->get_available_variations();
foreach ($variations as $key => $value) {
?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<?php
if(!empty($value['attributes'])){
foreach ($value['attributes'] as $attr_key => $attr_value) {
?>
<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
<?php
}
}
?>
<table>
<tbody>
<tr>
<td>
<b><?php echo implode('/', $value['attributes']);?></b>
</td>
<td>
<?php echo $value['price_html'];?>
</td>
<td>
<a class="single_add_to_cart_button button alt" target="_blank" href="<?php echo get_post_meta($value['variation_id'], '_my_affiliate_url', true); ?>" ><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></a>
</td>
</tr>
</tbody>
</table>
</form>
<?php
}
}
It's been a while, so you may have resolved this. But anyone in the future who comes here looking for an answer like I did.
Replace:
add_action( 'woocommerce_process_product_meta_variable', 'variable_fields_process', 10, 1 );
with:
add_action( 'woocommerce_save_product_variation', 'variable_fields_process', 10, 2 );
Saving variants changed as of WooCommerce 2.4.4
Related
I have found this piece of code for functions.php it's getting me partway to where I want to be.
Code I am using found here Adding affiliate links to Woocommerce variations
Website with attached code in place
However
It is removing my dropdown variation selection & the variable product description and placing all variable product data in a table.
I also want to create a second input box in the variation set up to output custom button text for each 'add to basket' - so that I can put the affiliate retailer name.
I want to be able to add multiple affiliate retailer buttons (with custom text) per variation, not just one.
What I would like the added multiple affiliate retailer buttons to display per variation dropdown selection, showing below the variable product description and below the variable price.
All help hugely appreciated. I'm not proficient at writing code so will need any advice spelling out for me I am afraid. Thanks.
// Display Fields
add_action( 'woocommerce_product_after_variable_attributes', 'variable_fields', 10, 2 );
//JS to add fields for new variations
add_action( 'woocommerce_product_after_variable_attributes_js', 'variable_fields_js' );
// Save Fields
add_action( 'woocommerce_process_product_meta_variable', 'variable_fields_process', 10, 2 );
function variable_fields( $loop, $variation_data ) {
?>
<tr>
<td>
<div>
<label><?php _e( 'Affiliate URL', 'woocommerce' ); ?></label>
<input type="text" size="5" name="my_affiliate_url[<?php echo $loop; ?>]" value="<?php echo $variation_data['_my_affiliate_url'][0]; ?>"/>
</div>
</td>
</tr>
<?php
}
function variable_fields_js() {
?>
<tr>
<td>
<div>
<label><?php _e( 'My Custom Field', 'woocommerce' ); ?></label>
<input type="text" size="5" name="my_affiliate_url[' + loop + ']" />
</div>
</td>
</tr>
<?php
}
function variable_fields_process( $post_id ) {
if (isset( $_POST['variable_sku'] ) ) :
$variable_sku = $_POST['variable_sku'];
$variable_post_id = $_POST['variable_post_id'];
$variable_custom_field = $_POST['my_affiliate_url'];
for ( $i = 0; $i < sizeof( $variable_sku ); $i++ ) :
$variation_id = (int) $variable_post_id[$i];
if ( isset( $variable_custom_field[$i] ) ) {
update_post_meta( $variation_id, '_my_affiliate_url', stripslashes( $variable_custom_field[$i] ) );
}
endfor;
endif;
}
//front-end variations
function woocommerce_variable_add_to_cart() {
global $product, $post;
$variations = $product->get_available_variations();
foreach ($variations as $key => $value) {
?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<?php
if(!empty($value['attributes'])){
foreach ($value['attributes'] as $attr_key => $attr_value) {
?>
<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
<?php
}
}
?>
<table>
<tbody>
<tr>
<td>
<b><?php echo implode('/', $value['attributes']);?></b>
</td>
<td>
<?php echo $value['price_html'];?>
</td>
<td>
<a class="single_add_to_cart_button button alt" target="_blank" href="<?php echo get_post_meta($value['variation_id'], '_my_affiliate_url', true); ?>" ><?php echo apply_filters('single_add_to_cart_text', __( 'Add to cart', 'woocommerce' ), $product->product_type); ?></a>
</td>
</tr>
</tbody>
</table>
</form>
<?php
}
}
The above code seems to be overriding this script in variation.php
defined( 'ABSPATH' ) || exit;
?>
<script type="text/template" id="tmpl-variation-template">
<div class="woocommerce-variation-description">{{{ data.variation.variation_description }}}</div>
<div class="woocommerce-variation-price">{{{ data.variation.price_html }}}</div>
<div class="woocommerce-variation-custom_field">{{{ data.variation.custom_field}}}</div>
<div class="woocommerce-variation-availability">{{{ data.variation.availability_html }}}</div>
</script>
<script type="text/template" id="tmpl-unavailable-variation-template">
<p><?php esc_html_e( 'Sorry, this product is unavailable. Please choose a different combination.', 'woocommerce' ); ?></p>
</script>
I have some problems displaying the SKU for variations, I modified the Single Product Page to display the Variations as a List, this is the Code I used (functions of the the Theme, tried with a Standard Theme, no change)
function woocommerce_variable_add_to_cart() {
global $product, $post;
$variations = $product->get_available_variations();
foreach ($variations as $key => $value) {
?>
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>"method="post" enctype='multipart/form-data'>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<?php
if(!empty($value['attributes'])){
foreach ($value['attributes'] as $attr_key => $attr_value) {
?>
<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
<?php
}
}
?>
<table>
<tbody>
<tr>
<td>
<b><?php echo implode('/', $value['attributes']);?></b>
</td>
<td>
<?php echo $value['price_html'];?>
</td>
<td>
<div class="woocommerce-variation-add-to-cart variations_button">
<?php
do_action( 'woocommerce_before_add_to_cart_quantity' );
woocommerce_quantity_input( array(
'min_value' => apply_filters( 'woocommerce_quantity_input_min', $product->get_min_purchase_quantity(), $product ),
'max_value' => apply_filters( 'woocommerce_quantity_input_max', $product->get_max_purchase_quantity(), $product ),
'input_value' => isset( $_POST['quantity'] ) ? wc_stock_amount( $_POST['quantity'] ) : $product->get_min_purchase_quantity(),
) );
do_action( 'woocommerce_after_add_to_cart_quantity' );
?>
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
<input type="hidden" name="add-to-cart" value="<?php echo absint( $product->get_id() ); ?>" />
<input type="hidden" name="product_id" value="<?php echo absint( $product->get_id() ); ?>" />
<input type="hidden" name="variation_id" class="variation_id" value="0" /></div>
<?php
global $product;
?>
<div class>
<?php if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variation' ) ) ) : ?>
<span class="sku_wrapper"><?php esc_html_e( 'Artikelnummer: ', 'woocommerce' ); ?> <span class="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : esc_html__( 'N/A', 'woocommerce' ); ?></span></span>
<?php endif;?>
</div>
</td>
</tr>
</tbody>
</table>
</form>
<?php
}
}
The only thing not working is getting the SKU of the Variation, instead it gets the SKU of the Product itself or nothing at all (this is the case with the code below, any hint/help would be appreciated. I also tried implent this Variable Product Sku not Working
but it didn't work either
Thanks in Advance (I hade trouble with getting all the coe to display in the code window so I have to use the snippet function, appologies for that)
Your code was a bit hard to read but try using get_post_meta with the variation post id.
$variation_sku = get_post_meta( $value['variation_id'] , '_sku', TRUE );
See if that works.
I have created a custom page to show Specific Product Variation in to table list.
Here is the code:
<h1> PRODUCT TABLE LIST </h1>
<table>
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Message</th>
<th>Price</th>
<th>Quantity</th>
<th>Total Quantity</th>
<th></th>
</tr>
</thead>
<tbody class="products">
<?php
$args = array(
'post_type' => array('product', 'product_variation'),
'posts_per_page' => 5,
'product_cat' => '',
'post__in' => array( 521, 695, 852, 457, 961, 188, 399, 80, 109, 182, 108, 184, 171, 206, 197 ), // 15 products
'orderby' => 'id',
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1 );
$wp_query = new WP_Query( $args );
while ( $wp_query->have_posts() ) : $wp_query->the_post(); global $product; ?>
<?php if ( $product->is_type( 'variable' ) ) { ?>
<?php show_variable_products_list(); ?>
<?php
}
else {
?>
<tr class="product-<?php echo esc_attr( $product->id ); ?>">
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
<a href="<?php echo get_permalink( $wp_query->post->ID ) ?>" title="<?php echo esc_attr($wp_query->post->post_title ? $wp_query->post->post_title : $wp_query->post->ID); ?>">
<td class="image">
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $wp_query->post->ID )) echo get_the_post_thumbnail($wp_query->post->ID, 'wh_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="150px" height="150px" />'; ?>
</td>
<td class="title">
<h3><?php the_title(); ?></h3>
</td>
<td class="note">
<?php wholesale_msg_note(); ?>
<?php wholesale_letter_note(); ?>
</td>
<td class="price">
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">
<?php echo get_woocommerce_currency_symbol(); ?>
</span>
<?php echo $product->get_price() ?>
</span>
</td>
</a>
<td class="quantity-cs">
<table>
<tr>
<?php echo wholesale_sc_note(); ?>
</tr>
<tr>
<?php echo wholesale_kw_note(); ?>
</tr>
</table>
</td>
<td class="quantity-total">
<?php //woocommerce_quantity_input(); //This function generates the quantity field. ?>
<div class="quantity">
<input type="number" step="1" min="1" max="" name="quantity" value="1" title="Qty" class="input-text qty text" size="4" pattern="[0-9]*" inputmode="numeric" />
</div>
</td>
<td class="button">
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $product->id ); ?>" />
<input type="hidden" name="variation_id" class="variation_id" value="0" />
<button type="submit" class="button buy-now-btn cart-btn product_type_simple add_to_cart_button ajax_add_to_cart" />Add to Cart</button>
</td>
</form>
<?php
}
?>
</tr>
</tbody>
<?php endwhile; ?>
</table><!--/.products-->
<div>
<?php previous_posts_link( 'Older Posts' ); ?>
<?php next_posts_link( 'New Posts' , $wp_query->max_num_pages ); ?>
</div>
<?php
/*
PAGINATION
*/
if ( function_exists( 'wp_pagenavi' ) ) {
?>
<div id="pagination">
<?php wp_pagenavi( array( 'query' => $wp_query ) ); ?>
</div>
<?php } ?>
<?php wp_reset_query(); ?>
?>
Both the pagination works great for simple products but I am also using variable products to show here in this table format.
Here is the code:
function show_variable_products_list(){
global $product, $post;
$variations = find_valid_variations();
// Check if the special 'price_grid' meta is set, if it is, load the default template:
if ( get_post_meta($post->ID, 'price_grid', true) ) {
// Enqueue variation scripts
wp_enqueue_script( 'wc-add-to-cart-variation' );
// Load the template
wc_get_template( 'woocommerce/single-product/add-to-cart/variable.php', array(
'available_variations' => $product->get_available_variations(),
'attributes' => $product->get_variation_attributes(),
'selected_attributes' => $product->get_variation_default_attributes()
) );
return;
}
// Cool, lets do our own template!
?>
<?php
foreach ($variations as $key => $value) {
if( !$value['variation_is_visible'] ) continue;
?>
<tr class="product-<?php echo esc_attr( $product->id ); ?> variation-<?php echo $value['variation_id']?>">
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( json_encode( $available_variations ) ) ?>">
<td class="image">
<?php echo '<img src="'.$value['image_src'].'" alt="'.$product->get_title().'-'.$value['variation_id'].'" width="150px" height="150px" />'; ?>
</td>
<td class="title">
<h3><?php the_title(); ?></h3><br />
<b><?php
/*
- '.get_term_by().'
foreach($value['attributes'] as $key => $val ) {
$val = str_replace(array('-','_'), ' ', $val);
printf( '<span class="attr attr-%s">%s</span>', $key, ucwords($ival) );
}
*/
foreach($value['attributes'] as $attr_name => $attr_value ) {
$attr_name = substr($attr_name, 10);
$attr = get_term_by('slug', $attr_value, $attr_name);
$attr_value = $attr->name;
echo $attr_value, ' ';
//echo implode ('/', $attr_value );
//echo $attr->name;
//$attr_implode_name = implode(",", $value['attributes']);
//echo $attr_implode_name;
}
?></b>
</td>
<td class="note">
<?php wholesale_msg_note(); ?>
<?php wholesale_letter_note(); ?>
</td>
<td class="price">
<?php echo $value['price_html'];?>
</td>
<td class="keyblade">
<table>
<tr>
<?php echo wholesale_sc_note(); ?>
</tr>
<tr>
<?php echo wholesale_kw_note(); ?>
</tr>
</table>
</td>
<?php if( $value['is_in_stock'] ) { ?>
<td>
<?php woocommerce_quantity_input(); ?>
</td>
<td>
<?php
if(!empty($value['attributes'])){
foreach ($value['attributes'] as $attr_key => $attr_value) {
?>
<input type="hidden" name="<?php echo $attr_key?>" value="<?php echo $attr_value?>">
<?php
}
}
?>
<button type="submit" class="single_add_to_cart_button btn btn-primary ajax_add_to_cart"><span class="glyphicon glyphicon-tag"></span> Add to cart</button>
<input type="hidden" name="variation_id" value="<?php echo $value['variation_id']?>" />
<input type="hidden" name="product_id" value="<?php echo esc_attr( $post->ID ); ?>" />
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $post->ID ); ?>" />
<?php } else { ?>
<p class="stock out-of-stock"><?php _e( 'This product is currently out of stock and unavailable.', 'woocommerce' ); ?></p>
<?php } ?>
</td>
</form>
</tr>
<?php } ?>
<?php
}
function find_valid_variations() {
global $product;
$variations = $product->get_available_variations();
$attributes = $product->get_attributes();
$new_variants = array();
// Loop through all variations
foreach( $variations as $variation ) {
// Peruse the attributes.
// 1. If both are explicitly set, this is a valid variation
// 2. If one is not set, that means any, and we must 'create' the rest.
$valid = true; // so far
foreach( $attributes as $slug => $args ) {
if( array_key_exists("attribute_$slug", $variation['attributes']) && !empty($variation['attributes']["attribute_$slug"]) ) {
// Exists
} else {
// Not exists, create
$valid = false; // it contains 'anys'
// loop through all options for the 'ANY' attribute, and add each
foreach( explode( '|', $attributes[$slug]['value']) as $attribute ) {
$attribute = trim( $attribute );
$new_variant = $variation;
$new_variant['attributes']["attribute_$slug"] = $attribute;
$new_variants[] = $new_variant;
//$woocommerce->attribute_label
}
}
}
// This contains ALL set attributes, and is itself a 'valid' variation.
if( $valid )
$new_variants[] = $variation;
}
return $new_variants;
}
add_filter( 'woocommerce_variable_add_to_cart', 'show_variable_products_list', 10, 2 );
The problem is if the page have 2 simple product & 3 variable product with say 3 variations each then the page shows 2 + 3x3 = 11 products instead of 5.
What am I doing wrong? How can I show 5 products in each page even with variable products?
I want to show specific products in a table list view with their own custom field for specific user; couldn't achieve this with any plugins so started to code my own. Only this user/wholesaler will view this page.
But before going that far in the code I got stuck on "ADD TO CART" Button submission. Whichever product I try to add only the last product in the row gets submitted.
Here's the code:
<h1> PRODUCT TABLE LIST </h1>
<table>
<thead>
<tr>
<th></th>
<th>Product</th>
<th>Note Box</th>
<th>Price</th>
<th>Choose Quantiy</th>
<th>Product Total Quantity</th>
<th></th>
</tr>
</thead>
<tbody class="products">
<?php
$args = array(
'post_type' => 'product',
'posts_per_page' => 15,
'product_cat' => '',
'post__in' => array( 481, 478, 934 ),
'orderby' => 'title' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>
<tr class="product-<?php echo esc_attr( $product->id ); ?>">
<a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">
<td>
<?php woocommerce_show_product_sale_flash( $post, $product ); ?>
<?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>
</td>
<td>
<h3><?php the_title(); ?></h3>
</td>
<td>
<input type="text" placeholder="Choose up to 16 letters or Numbers" />
</td>
<td>
<span class="price">
<?php echo $product->get_price_html(); ?>
</span>
</td>
</a>
<td>
<table>
<tr>
<th>SC1</th>
<td><input type="number" name="quantity" min="1" max="100"></td>
</tr>
<tr>
<th>KW1</th>
<td><input type="number" name="quantity" min="1" max="100"></td>
</tr>
</table>
</td>
<td><input name="quantity" data-min="1" data-max="0" value="1" size="4" title="Qty" class="input-text qty text" maxlength="12" type="number"></td>
<td>
<input type="hidden" name="add-to-cart" value="<?php echo esc_attr( $product->id ); ?>" />
<button type="submit" class="single_add_to_cart_button button alt"><?php echo esc_html( $product->single_add_to_cart_text() ); ?></button>
</td>
</tr>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</tbody>
</table>
I have tried to use woocommerce_template_loop_add_to_cart( $loop->post, $product) but it doesn't submit the quantity value.
Use form <form> after your table row <tr>
For single products use:
<form action="<?php echo esc_url( $product->add_to_cart_url() ); ?>" class="cart" method="post" enctype='multipart/form-data'>
For variable products use:
<form class="variations_form cart" method="post" enctype='multipart/form-data' data-product_id="<?php echo absint( $product->id ); ?>" data-product_variations="<?php echo htmlspecialchars( json_encode( $available_variations ) ) ?>">
there is no need to create different tempalte for woo commerce cart. woocommerce give you to chnage this its own templates.
copy the files under templates folder from woocommerce plugin and paste these files to you theme folder under the "woocommerce" folder. (you have to create woocommerce folder in your theme). now you can modify woocommerce templates.
I need to add a list of check-boxes to custom taxonomy add/edit form.
I have this code for adding a text field for custom taxonomy form in my plugin and it works fine:
<?php
function taxonomy_edit_meta_field($term) {
$t_id = $term->term_id;
$term_meta = get_option( "taxonomy_$t_id" );
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]"><?php _e( 'Term:' ); ?></label></th>
<td>
<input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="<?php echo esc_attr( $term_meta['custom_term_meta'] ) ? esc_attr( $term_meta['custom_term_meta'] ) : ''; ?>">
</td>
</tr>
<?php
}
add_action( 'product_cat_edit_form_fields', 'taxonomy_edit_meta_field', 10, 2 );
function save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
update_option( "taxonomy_$t_id", $term_meta );
}
}
add_action( 'edited_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
add_action( 'create_product_cat', 'save_taxonomy_custom_meta', 10, 2 );
How I can add a list of check-boxes in the same way?
There were a problem with the saving not checked check-box input.
I have fixed it with input type="hidden" with the same value of "name" attribute, as in check-box input.
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]"><?php _e( 'Color:' ); ?></label></th>
<td>
<input type="hidden" value="0" name="term_meta[pa_color_attr]">
<input type="checkbox" <?php echo (!empty($term_meta['pa_color_attr']) ? ' checked="checked" ' : 'test'); ?> value="1" name="term_meta[pa_color_attr]" />
</td>
</tr>
you need to change the name of the hook.
add_action( 'edited_custom_tax', 'save_taxonomy_custom_meta', 10, 2 );