Woocommerce Product Variations Pagination not working - php

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?

Related

Add multiple affiliate links to Woocommerce Variations with custom button text

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>

YITH WooCommerce Wishlist: Help me show the first item / product thumbnail within the sidebar widget and wishlist manage areas?

I am using YITH Wishlist within WooCommerce, WordPress.
Within an individual wishlist - it displays the image, with 'remove from list', the product title and a link through to the individual product all working.
So going one step higher up the 'folders' when I display the individual wishlists within the Manage Wishlists page, I am only able to show the name of the list and the link through to that individual list where you can see all the products grouped. This is where I wish to be able to display the 'first product within that individual wishlist' 's first image or thumbnail.
I have tried and broken the script numerous times. How can I write a script that will grab that image and let me display it within the Manage Wishlist's page? Better yet, is there a shortcode that does this for me (if there is such a thing)?
Here is the pretty much stock relevant template files...
This is the manage page template (if you Ctrl+F for 'I WANT TO SHOW IMAGE HERE' to see where I want to pull image through) - where I want to display image:
<?php
/**
* Wishlist manage template
*
* #author Your Inspiration Themes
* #package YITH WooCommerce Wishlist
* #version 2.0.5
*/
if ( ! defined( 'YITH_WCWL' ) ) {
exit;
} // Exit if accessed directly
?>
<form id="yith-wcwl-form" action="<?php echo esc_url( YITH_WCWL()->get_wishlist_url( 'manage' ) ) ?>" method="post">
<!-- TITLE -->
<?php
do_action( 'yith_wcwl_before_wishlist_title' );
if( ! empty( $page_title ) ) {
echo apply_filters( 'yith_wcwl_wishlist_title', '<h2 class="h1 blue lh2 mt2 mb0 p0">Manage My Boards</h2>' );
}
do_action( 'yith_wcwl_before_wishlist_manage' );
?>
<table class="shop_table cart wishlist_table wishlist_manage_table" cellspacing="0" >
<thead>
<tr>
<th class="wishlist-name">
<span class="nobr">
Boards
<?php // echo apply_filters( 'yith_wcwl_wishlist_manage_name_heading', __( 'Wishlists', 'yith-woocommerce-wishlist' ) ) ?>
</span>
</th>
<?php /* ?>
<th class="wishlist-privacy">
<span class="nobr">
<?php echo apply_filters( 'yith_wcwl_wishlist_manage_privacy_heading', __( 'Privacy', 'yith-woocommerce-wishlist' ) ) ?>
</span>
</th>
<?php */ ?>
<th class="wishlist-delete">
<span class="nobr">
<?php echo apply_filters( 'yith_wcwl_wishlist_manage_delete_heading', __( 'Delete', 'yith-woocommerce-wishlist' ) ) ?>
</span>
</th>
</tr>
</thead>
<tbody>
<tr>
<td class="wishlist-name">
<a title="<?php echo $default_wishlist_title ?>" class="wishlist-anchor" href="<?php echo YITH_WCWL()->get_wishlist_url( 'user' . '/' . $current_user_id ) ?>">
<?php echo $default_wishlist_title ?>
</a>
</td>
<?php /* ?>
<td class="wishlist-privacy">
<?php echo apply_filters( 'yith_wcwl_wishlist_manage_default_privacy', __( 'Public', 'yith-woocommerce-wishlist' ) )?>
</td>
<?php */ ?>
<td class="wishlist-delete"></td>
</tr>
<?php
$wishlist_count = 0;
if( ! empty( $user_wishlists ) ):
?>
<?php foreach( $user_wishlists as $wishlist ): ?>
<?php if( ! $wishlist['is_default'] ): ?>
<tr>
<td class="wishlist-name">
<a title="<?php echo $wishlist['wishlist_name'] ?>" class="wishlist-anchor" href="<?php echo YITH_WCWL()->get_wishlist_url( 'view' . '/' . $wishlist['wishlist_token'] ) ?>">
<!-- I WANT TO SHOW IMAGE HERE (OF THE FIRST PRODUCT IN THE WISHLIST CURRENTLY BEING LOOPED THROUGH) -->
<?php echo $wishlist['wishlist_name'] ?>
</a>
</td>
<?php /* ?>
<td class="wishlist-privacy">
<select name="wishlist_options[<?php echo $wishlist['ID'] ?>][wishlist_privacy]" class="wishlist-visibility selectBox">
<option value="0" class="public-visibility" <?php selected( $wishlist['wishlist_privacy'], 0 ) ?> ><?php echo apply_filters( 'yith_wcwl_public_wishlist_visibility', __( 'Public', 'yith-woocommerce-wishlist' ) )?></option>
<option value="1" class="shared-visibility" <?php selected( $wishlist['wishlist_privacy'], 1 ) ?> ><?php echo apply_filters( 'yith_wcwl_shared_wishlist_visibility', __( 'Shared', 'yith-woocommerce-wishlist' ) )?></option>
<option value="2" class="private-visibility" <?php selected( $wishlist['wishlist_privacy'], 2 ) ?> ><?php echo apply_filters( 'yith_wcwl_private_wishlist_visibility', __( 'Private', 'yith-woocommerce-wishlist' ) )?></option>
</select>
</td>
<?php */ ?>
<td class="wishlist-delete">
<!-- <input type="checkbox" value="yes" name="wishlist_options[<?php echo $wishlist['ID'] ?>][delete]"/> -->
<a class="button" href="<?php echo esc_url( add_query_arg( 'wishlist_id', $wishlist['ID'], wp_nonce_url( YITH_WCWL()->get_wishlist_url( 'manage' ), 'yith_wcwl_delete_action', 'yith_wcwl_delete' ) ) ) ?>"><?php _e( 'Delete', 'yith-woocommerce-wishlist' ) ?></a>
</td>
</tr>
<?php
$wishlist_count ++;
endif;
?>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<a class="btn button create-new-wishlist" href="<?php echo YITH_WCWL()->get_wishlist_url( 'create' ) ?>">
<?php echo apply_filters( 'yith_wcwl_create_new_wishlist_icon', '<i class="icon-plus"></i>' )?>
<?php echo apply_filters( 'yith_wcwl_create_new_wishlist_title', __( 'Create a new board', 'yith-woocommerce-wishlist' ) )?>
</a>
<?php if( ! empty( $user_wishlists ) && $wishlist_count ): ?>
<button class="submit-wishlist-changes">
<?php echo apply_filters( 'yith_wcwl_mange_wishlist_icon', '<i class="icon-ok"></i>' )?>
<?php _e( 'Save Settings', 'yith-woocommerce-wishlist' ) ?>
</button>
<?php endif; ?>
</td>
</tr>
</tfoot>
</table>
<?php wp_nonce_field( 'yith_wcwl_manage_action', 'yith_wcwl_manage' )?>
<?php do_action( 'yith_wcwl_after_wishlist_manage' ); ?>
</form>
This is the individual wishlist page, with the working Show Product Image script (Ctrl+F 'GRABBING THE IMAGE SUCCESSFULLY' to get to relevant code) - where I can see a working example of pulling the image from a product through:
<?php
/**
* Wishlist page template
*
* #author Your Inspiration Themes
* #package YITH WooCommerce Wishlist
* #version 2.0.12
*/
if ( ! defined( 'YITH_WCWL' ) ) {
exit;
} // Exit if accessed directly
?>
<script type="text/javascript">
var root = document.documentElement;
root.className += ' wishlist-view';
</script>
<?php do_action( 'yith_wcwl_before_wishlist_form', $wishlist_meta ); ?>
<?php
function cmp($a, $b) {
if ($a == $b) {
return 0;
}
return ($a < $b) ? -1 : 1;
}
uasort($users_wishlists, 'cmp');
?>
<?php /* ?>
<pre><code>
<?php
print_r($wishlist_items);
// print_r($users_wishlists);
?>
</code></pre>
<?php */ ?>
<!--
<div class="my-materials-sidebar bg-dark-blue white lg:absolute top-0 left-0 bottom-0">
<div class="bg-darken-3 p2 lg:p3 height-100 overflow-auto">
<h3 class="h1 mt0">My Materials</h3>
<h3 class="h2 lg:h1 mb1">My Boards</h3>
<ul class="list-reset my3 p0 uppercase lg:h3">
<li>Add new board</li>
<li>Manage boards</li>
</ul>
<ul class="list-reset m0 p0 uppercase lg:h3 boards">
<?php foreach ($users_wishlists as $users_wishlist) : ?>
<?php
$token = $users_wishlist['wishlist_token'];
$name = $users_wishlist['wishlist_name'];
?>
<?php /* <pre><code><?php print_r($users_wishlist); ?></code></pre> */ ?>
<li>
<?php if( $name ) : ?>
<a href="/my-materials/view/<?php echo $token; ?>">
<?php echo $name; ?>
</a>
<?php else : ?>
<a href="/my-materials">
Main board
</a>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<ul class="list-reset m0 p0 uppercase lg:h3">
<li>
My account
</li>
<li>
Log out
</li>
</ul>
</div>
</div>
-->
<form id="yith-wcwl-form" action="<?php echo $form_action ?>" method="post" class="woocommerce">
<?php wp_nonce_field( 'yith-wcwl-form', 'yith_wcwl_form_nonce' ) ?>
<!-- TITLE -->
<?php
do_action( 'yith_wcwl_before_wishlist_title', $wishlist_meta );
if( ! empty( $page_title ) ) :
?>
All Boards
<?php if( count( $wishlist_items ) > 0 ) : ?>
<a href="#" class="btn dark-grey hover:black right" data-edit-board>Edit Board</a>
<?php else : ?>
<?php endif; ?>
<div class="wishlist-title <?php echo ( $is_custom_list ) ? 'wishlist-title-with-form' : ''?>">
<?php echo apply_filters( 'yith_wcwl_wishlist_title', '<h2 class="h1 blue lh2 mt2 mb0 p0">' . $page_title . '</h2>' ); ?>
<?php /* if( $is_custom_list ): ?>
<a class="btn button show-title-form">
<?php echo apply_filters( 'yith_wcwl_edit_title_icon', '<i class="fa fa-pencil"></i>' )?>
<?php _e( 'Edit title', 'yith-woocommerce-wishlist' ) ?>
</a>
<?php endif; */ ?>
</div>
<?php if( $is_custom_list ): ?>
<div class="hidden-title-form">
<input type="text" value="<?php echo $page_title ?>" name="wishlist_name"/>
<button class="button">
<?php echo apply_filters( 'yith_wcwl_save_wishlist_title_icon', '<i class="fa fa-check fa-fw"></i>' )?>
<span>
<?php _e( 'Save', 'yith-woocommerce-wishlist' )?>
</span>
</button>
<a class="hide-title-form btn button">
<?php echo apply_filters( 'yith_wcwl_cancel_wishlist_title_icon', '<i class="fa fa-remove fa-fw"></i>' )?>
<span>
<?php _e( 'Cancel', 'yith-woocommerce-wishlist' )?>
</span>
</a>
</div>
<?php endif; ?>
<?php
endif;
do_action( 'yith_wcwl_before_wishlist', $wishlist_meta ); ?>
<?php /* ?>
<ul class="products columns-4">
<?php if( count( $wishlist_items ) > 0 ) :
$added_items = array();
foreach( $wishlist_items as $item ) :
global $product;
$item['prod_id'] = yit_wpml_object_id ( $item['prod_id'], 'product', true );
if( in_array( $item['prod_id'], $added_items ) ){
continue;
}
$added_items[] = $item['prod_id'];
$product = wc_get_product( $item['prod_id'] );
$availability = $product->get_availability();
$stock_status = $availability['class'];
if( $product && $product->exists() ) :
?>
<li class="product">
<a href="<?php echo esc_url( get_permalink( apply_filters( 'woocommerce_in_cart_product', $item['prod_id'] ) ) ) ?>">
<?php echo $product->get_image() ?>
<h2 class="woocommerce-loop-product__title"><?php echo apply_filters( 'woocommerce_in_cartproduct_obj_title', $product->get_title(), $product ) ?></h2>
<?php do_action( 'yith_wcwl_table_after_product_name', $item ); ?>
</a>
<?php if( $is_user_owner ): ?>
<div class="product-remove">
×
</div>
<?php endif; ?>
<?php if( $available_multi_wishlist && is_user_logged_in() && count( $users_wishlists ) > 1 && $move_to_another_wishlist && $is_user_owner ): ?>
<select class="change-wishlist selectBox-">
<option value=""><?php _e( 'Move', 'yith-woocommerce-wishlist' ) ?></option>
<?php
foreach( $users_wishlists as $wl ):
if( $wl['wishlist_token'] == $wishlist_meta['wishlist_token'] ){
continue;
}
?>
<option value="<?php echo esc_attr( $wl['wishlist_token'] ) ?>">
<?php
$wl_title = ! empty( $wl['wishlist_name'] ) ? esc_html( $wl['wishlist_name'] ) : esc_html( $default_wishlsit_title );
if( $wl['wishlist_privacy'] == 1 ){
$wl_privacy = __( 'Shared', 'yith-woocommerce-wishlist' );
}
elseif( $wl['wishlist_privacy'] == 2 ){
$wl_privacy = __( 'Private', 'yith-woocommerce-wishlist' );
}
else{
$wl_privacy = __( 'Public', 'yith-woocommerce-wishlist' );
}
// echo sprintf( '%s - %s', $wl_title, $wl_privacy );
echo sprintf( '%s', $wl_title );
?>
</option>
<?php
endforeach;
?>
</select>
<?php endif; ?>
</li>
<?php
endif;
endforeach;
else: ?>
<?php endif; ?>
</ul>
<?php */ ?>
<?php ?>
<!-- WISHLIST TABLE -->
<table class="shop_table cart wishlist_table" data-pagination="<?php echo esc_attr( $pagination )?>" data-per-page="<?php echo esc_attr( $per_page )?>" data-page="<?php echo esc_attr( $current_page )?>" data-id="<?php echo $wishlist_id ?>" data-token="<?php echo $wishlist_token ?>">
<?php $column_count = 2; ?>
<thead>
<tr>
<?php if( $show_cb ) : ?>
<th class="product-checkbox">
<input type="checkbox" value="" name="" id="bulk_add_to_cart"/>
</th>
<?php
$column_count ++;
endif;
?>
<?php if( $is_user_owner ): ?>
<th class="product-remove"></th>
<?php
$column_count ++;
endif;
?>
<th class="product-thumbnail"></th>
<th class="product-name">
<span class="nobr"><?php echo apply_filters( 'yith_wcwl_wishlist_view_name_heading', __( 'Product Name', 'yith-woocommerce-wishlist' ) ) ?></span>
</th>
<?php if( $show_price ) : ?>
<th class="product-price">
<span class="nobr">
<?php echo apply_filters( 'yith_wcwl_wishlist_view_price_heading', __( 'Unit Price', 'yith-woocommerce-wishlist' ) ) ?>
</span>
</th>
<?php
$column_count ++;
endif;
?>
<?php if( $show_stock_status ) : ?>
<th class="product-stock-status">
<span class="nobr">
<?php echo apply_filters( 'yith_wcwl_wishlist_view_stock_heading', __( 'Stock Status', 'yith-woocommerce-wishlist' ) ) ?>
</span>
</th>
<?php
$column_count ++;
endif;
?>
<?php if( $show_last_column ) : ?>
<th class="product-move"></th>
<?php
$column_count ++;
endif;
?>
</tr>
</thead>
<tbody>
<?php
if( count( $wishlist_items ) > 0 ) :
$added_items = array();
foreach( $wishlist_items as $item ) :
global $product;
$item['prod_id'] = yit_wpml_object_id ( $item['prod_id'], 'product', true );
if( in_array( $item['prod_id'], $added_items ) ){
continue;
}
$added_items[] = $item['prod_id'];
$product = wc_get_product( $item['prod_id'] );
$availability = $product->get_availability();
$stock_status = $availability['class'];
if( $product && $product->exists() ) :
?>
<tr id="yith-wcwl-row-<?php echo $item['prod_id'] ?>" data-row-id="<?php echo $item['prod_id'] ?>">
<?php if( $show_cb ) : ?>
<td class="product-checkbox">
<input type="checkbox" value="<?php echo esc_attr( $item['prod_id'] ) ?>" name="add_to_cart[]" <?php echo ( ! $product->is_type( 'simple' ) ) ? 'disabled="disabled"' : '' ?>/>
</td>
<?php endif ?>
<?php if( $is_user_owner ): ?>
<td class="product-remove">
<div>
×
</div>
</td>
<?php endif; ?>
<td class="product-thumbnail">
<a href="<?php echo esc_url( get_permalink( apply_filters( 'woocommerce_in_cart_product', $item['prod_id'] ) ) ) ?>">
<!-- THIS IS GRABBING THE IMAGE SUCCESSFULLY -->
<?php echo $product->get_image() ?>
<h2 class="product-name"><?php echo apply_filters( 'woocommerce_in_cartproduct_obj_title', $product->get_title(), $product ) ?></h2>
<?php do_action( 'yith_wcwl_table_after_product_name', $item ); ?>
</a>
</td>
<?php /* ?>
<td class="product-name">
<?php echo apply_filters( 'woocommerce_in_cartproduct_obj_title', $product->get_title(), $product ) ?>
<?php do_action( 'yith_wcwl_table_after_product_name', $item ); ?>
</td>
<?php */ ?>
<?php if( $show_price ) : ?>
<td class="product-price">
<?php
$base_product = $product->is_type( 'variable' ) ? $product->get_variation_regular_price( 'max' ) : $product->get_price();
echo $base_product ? $product->get_price_html() : apply_filters( 'yith_free_text', __( 'Free!', 'yith-woocommerce-wishlist' ) );
?>
</td>
<?php endif ?>
<?php if( $show_stock_status ) : ?>
<td class="product-stock-status">
<?php echo $stock_status == 'out-of-stock' ? '<span class="wishlist-out-of-stock">' . __( 'Out of Stock', 'yith-woocommerce-wishlist' ) . '</span>' : '<span class="wishlist-in-stock">' . __( 'In Stock', 'yith-woocommerce-wishlist' ) . '</span>'; ?>
</td>
<?php endif ?>
<?php if( $show_last_column ): ?>
<td class="product-move">
<!-- Date added -->
<?php
if( $show_dateadded && isset( $item['dateadded'] ) ):
echo '<span class="dateadded">' . sprintf( __( 'Added on : %s', 'yith-woocommerce-wishlist' ), date_i18n( get_option( 'date_format' ), strtotime( $item['dateadded'] ) ) ) . '</span>';
endif;
?>
<!-- Add to cart button -->
<?php if( $show_add_to_cart && isset( $stock_status ) && $stock_status != 'out-of-stock' ): ?>
<?php woocommerce_template_loop_add_to_cart(); ?>
<?php endif ?>
<!-- Change wishlist -->
<?php if( $available_multi_wishlist && is_user_logged_in() && count( $users_wishlists ) > 1 && $move_to_another_wishlist && $is_user_owner ): ?>
<div class="product-move-trigger">
<!-- <img src="<?php echo get_template_directory_uri(); ?>/assets/img/plus-white.svg" alt="" class=""> -->
</div>
<div class="product-move-dropdown">
<h3>Move to Board</h3>
<select class="change-wishlist selectBox- select">
<option value=""><?php _e( 'Choose...', 'yith-woocommerce-wishlist' ) ?></option>
<?php
foreach( $users_wishlists as $wl ):
if( $wl['wishlist_token'] == $wishlist_meta['wishlist_token'] ){
continue;
}
?>
<option value="<?php echo esc_attr( $wl['wishlist_token'] ) ?>">
<?php
$wl_title = ! empty( $wl['wishlist_name'] ) ? esc_html( $wl['wishlist_name'] ) : esc_html( $default_wishlsit_title );
if( $wl['wishlist_privacy'] == 1 ){
$wl_privacy = __( 'Shared', 'yith-woocommerce-wishlist' );
}
elseif( $wl['wishlist_privacy'] == 2 ){
$wl_privacy = __( 'Private', 'yith-woocommerce-wishlist' );
}
else{
$wl_privacy = __( 'Public', 'yith-woocommerce-wishlist' );
}
if ( $wl_title == 'My Materials' ) {
$wl_title = 'Main board';
}
// echo sprintf( '%s - %s', $wl_title, $wl_privacy );
echo sprintf( '%s', $wl_title );
?>
</option>
<?php
endforeach;
?>
</select>
</div>
<?php endif; ?>
<!-- Remove from wishlist -->
<?php if( $is_user_owner && $repeat_remove_button ): ?>
<?php _e( 'Remove', 'yith-woocommerce-wishlist' ) ?>
<?php endif; ?>
</td>
<?php endif; ?>
</tr>
<?php
endif;
endforeach;
else: ?>
<tr class="empty">
<td colspan="<?php echo esc_attr( $column_count ) ?>" class="wishlist-empty"><?php echo apply_filters( 'yith_wcwl_no_product_to_remove_message', __( 'No items have been added to this board yet', 'yith-woocommerce-wishlist' ) ) ?></td>
</tr>
<?php
endif;
if( ! empty( $page_links ) ) : ?>
<tr class="pagination-row">
<td colspan="<?php echo esc_attr( $column_count ) ?>"><?php echo $page_links ?></td>
</tr>
<?php endif ?>
</tbody>
<tfoot>
<tr>
<td colspan="<?php echo esc_attr( $column_count ) ?>">
<?php if( $show_cb ) : ?>
<div class="custom-add-to-cart-button-cotaniner">
<?php echo apply_filters( 'yith_wcwl_custom_add_to_cart_text', __( 'Add the selected products to the cart', 'yith-woocommerce-wishlist' ) ) ?>
</div>
<?php endif; ?>
<?php if ( $is_user_owner && $show_ask_estimate_button && $count > 0 ): ?>
<div class="ask-an-estimate-button-container">
<a href="<?php echo ( $additional_info || ! is_user_logged_in() ) ? '#ask_an_estimate_popup' : $ask_estimate_url ?>" class="btn button ask-an-estimate-button" <?php echo ( $additional_info ) ? 'data-rel="prettyPhoto[ask_an_estimate]"' : '' ?> >
<?php echo apply_filters( 'yith_wcwl_ask_an_estimate_icon', '<i class="fa fa-shopping-cart"></i>' )?>
<?php echo apply_filters( 'yith_wcwl_ask_an_estimate_text', __( 'Ask for an estimate', 'yith-woocommerce-wishlist' ) ) ?>
</a>
</div>
<?php endif; ?>
<?php
do_action( 'yith_wcwl_before_wishlist_share', $wishlist_meta );
if ( is_user_logged_in() && $is_user_owner && ! $is_private && $share_enabled ){
yith_wcwl_get_template( 'share.php', $share_atts );
}
do_action( 'yith_wcwl_after_wishlist_share', $wishlist_meta );
?>
</td>
</tr>
</tfoot>
</table>
<?php ?>
<?php wp_nonce_field( 'yith_wcwl_edit_wishlist_action', 'yith_wcwl_edit_wishlist' ); ?>
<?php if( ! $is_default ): ?>
<input type="hidden" value="<?php echo $wishlist_token ?>" name="wishlist_id" id="wishlist_id">
<?php endif; ?>
<?php do_action( 'yith_wcwl_after_wishlist', $wishlist_meta ); ?>
</form>
<?php do_action( 'yith_wcwl_after_wishlist_form', $wishlist_meta ); ?>
<?php if( $show_ask_estimate_button && ( ! is_user_logged_in() || $additional_info ) ): ?>
<div id="ask_an_estimate_popup">
<form action="<?php echo $ask_estimate_url ?>" method="post" class="wishlist-ask-an-estimate-popup">
<?php if( ! is_user_logged_in() ): ?>
<label for="reply_email"><?php echo apply_filters( 'yith_wcwl_ask_estimate_reply_mail_label', __( 'Your email', 'yith-woocommerce-wishlist' ) ) ?></label>
<input type="email" value="" name="reply_email" id="reply_email">
<?php endif; ?>
<?php if( ! empty( $additional_info_label ) ):?>
<label for="additional_notes"><?php echo esc_html( $additional_info_label ) ?></label>
<?php endif; ?>
<textarea id="additional_notes" name="additional_notes"></textarea>
<button class="btn button ask-an-estimate-button ask-an-estimate-button-popup" >
<?php echo apply_filters( 'yith_wcwl_ask_an_estimate_icon', '<i class="fa fa-shopping-cart"></i>' )?>
<?php echo apply_filters( 'yith_wcwl_ask_an_estimate_text', __( 'Ask for an estimate', 'yith-woocommerce-wishlist' ) ) ?>
</button>
</form>
</div>
<?php endif; ?>
I know this script cannot be directly copied as it is looking through product variables knowing which product it is looking through, I need to write something similar that will look inside the wishlist instead of inside the product.
I think I know what I need to do, I just have no idea how to do it.
I have tried simple stuff I predicted wouldn't work before even implementing it. Trying to guess shortcodes / scouring the web for a list of shortcodes.
Edit
Attempting to achieve this using 'simplehtmldom'...
I have downloaded and installed simplehtmldom then called it into the file:
<?php
$simplehtmldom = get_template_directory() . "/simplehtmldom/simple_html_dom.php";
include_once($simplehtmldom);
?>
Then gone on to try find the image within the wishlist by gathering the src of the first product in that wishlist:
<?php
$boardlink = YITH_WCWL()->get_wishlist_url( 'view' . '/' . $wishlist['wishlist_token'] );
$html = file_get_html($boardlink);
$wishlistimage = $html->find('.attachment-woocommerce_thumbnail', 0)->src;
?>
The variable $boardlink value has been taken from the href within the section:
<a title="<?php echo $wishlist['wishlist_name'] ?>" class="wishlist-anchor" href="<?php echo YITH_WCWL()->get_wishlist_url( 'view' . '/' . $wishlist['wishlist_token'] ) ?>">
So technically should / could work...
However, I get a range of errors:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /home/example/public_html/development/wp-content/themes/bolt/simplehtmldom/simple_html_dom.php on line 136
Warning: file_get_contents(): Failed to enable crypto in /home/example/public_html/development/wp-content/themes/bolt/simplehtmldom/simple_html_dom.php on line 136
Warning: file_get_contents(https://development.example.com/my-materials/view/9OW01M6785H9/): failed to open stream: operation failed in /home/example/public_html/development/wp-content/themes/bolt/simplehtmldom/simple_html_dom.php on line 136
This site doesn't have a valid SSL as it is just a staging dev site. The live site does have an SSL.
I think the main issue is with the wishlists being private to the user, I don't think we are able to scrape from these pages.

Variable SKU not showing on Single Page

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.

WooCommerce Custom Template Adding Only Last Product in the row to the cart

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.

Adding affiliate links to Woocommerce variations

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

Categories