Skip to content

Instantly share code, notes, and snippets.

@hakikz
Last active March 15, 2024 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakikz/a320e34cc991c0e91e59723ae45c363d to your computer and use it in GitHub Desktop.
Save hakikz/a320e34cc991c0e91e59723ae45c363d to your computer and use it in GitHub Desktop.
Snippets for PVT 1.4.0 Series
function pvtcs_auto_check_init(){
if( !class_exists('PVTFW_TABLE_PRO' )){
return;
}
add_filter('woocommerce_quantity_input_min', 'pvt_rewrite_value_zero');
add_filter('pvtfw_qtyargs_input_value', 'pvt_rewrite_value_zero');
function pvt_rewrite_value_zero(){
return 0;
}
add_action('wp_footer', function(){
?>
<script id="auto_check">
jQuery(document).ready(function($){
$("input[name=var_checkall]").click(function () {
if( ! $(this).is(':checked') ){
$( 'input[name=quantity]' ).val(0);
}
});
$( 'input.qty' ).on('keyup change', function(){
let qty = $(this).val();
if( qty > 0 ){
$(this).closest('tr').find('input[class=var_checkbox]').prop('checked', true);
$("#bulk_cart").prop("disabled",false);
}
else{
$(this).closest('tr').find('input[class=var_checkbox]').prop('checked', false);
$("#bulk_cart").prop("disabled",true);
}
var rowCount = $('.variant tbody tr').length;
if( $("input[name=var_val]:not(input[name=var_checkall]):checked").length == rowCount ){
$("input[name=var_checkall]").prop('checked', true);
}
else{
$("input[name=var_checkall]").prop('checked', false);
}
});
});
</script>
<?php
}, 100);
}
add_action( 'plugins_loaded', 'pvtcs_auto_check_init' );
// Change the bulk cart text (PVT Version 1.4.0+)
function pvt_bulk_cart_text_override(){
return _x( 'YOUR_CUSTOM_TEXT', 'Bulk Cart: Button Text', 'product-variant-table-for-woocommerce-pro' );
}
add_filter('pvtfw_table_bulk_cart_text', 'pvt_bulk_cart_text_override');
add_filter( 'pvtfw_columns_labels', function( $labels ){
if( wp_is_mobile() ){
$labels['image_link'] = __('Thumb', 'product-variant-table-for-woocommerce');
$labels['quantity'] = __('Qty', 'product-variant-table-for-woocommerce');
return $labels;
}
return $labels;
}, 10, 1 );

Add the following lines using the Code Snippets plugin. You can add the following lines inside your theme's functions.php file

remove_filter( 'pvt_print_plus_minus_qty_field', 'pvt_display_qty_plus_minus_button', 10, 1 );
add_filter( 'pvt_print_plus_minus_qty_field', function( $value ){ return woocommerce_quantity_input($value); });

Note: A child theme should use if you want to add the above lines inside your child theme's functions.php file

Display an additional column to display variation name and make it clickable for popup variation image

*Steps:

  • Add the following code using Code Snippets plugin.
  • Please enable Run Snippet Everywhere from code snippets code editor (bottom part)
  • Go to Variation Table settings and Reset Columns by click the red icon beside Select Columns to Show in the Variation Table
  • Uncheck Thumbnail & Attributes column. Then drag the Variation column at the top
add_filter('pvtfw_default_columns', function($default){
	// Example of extra column (with `dynamic` table data)
	$default['variation_name'] = "on";
	return $default;
});
add_filter('pvtfw_columns_labels', function($default){
	// Example of extra column (with `dynamic` table data)
	$default['variation_name'] = __('Variation', 'product-variant-table-for-woocommerce');
	return $default;
});
add_filter('pvtfw_extra_column_value', function($default, $key, $value, $single_variation){
	// Example of extra column (with `dynamic` table data)
	if( 'variation_name' === $key ){
		$thumb_size =  PVTFW_PRO_COMMON::pvtfw_pro_get_options()->thumb_size;
		$default = "<a class='pvtfw-popup-link' href='".wp_get_attachment_url( $single_variation->get_image_id() )."'>".ucwords( implode( ' , ',$single_variation->get_attributes())).wp_get_attachment_image( $single_variation->get_image_id(), array($thumb_size, $thumb_size), "", array( "class" => "pvtfw_pro_img_size pvtfw_pro_hide" ) )."</a>";
	}
	return $default;
}, 10, 4);
add_action('wp_head', function(){
	?>
		<style>
		img.pvtfw_pro_img_size.pvtfw_pro_hide {
			display: none;
		}
		</style>
	<?php
});
if ( !function_exists( 'pvt_get_price_html_with_discount' ) ){
function pvt_get_price_html_with_discount( $price_html, $single_variation ){
$active_price = $single_variation->get_price();
$regular_price = $single_variation->get_regular_price();
if ( 'yes' === get_option( 'woocommerce_calc_taxes' ) && 'incl' === get_option( 'woocommerce_tax_display_shop' ) ) {
$price = wc_get_price_including_tax( $single_variation );
}
else{
$price = $single_variation->get_sale_price();
}
if( $active_price !== $regular_price ) {
$saving_percentage = round( 100 - ( $active_price / $regular_price * 100 ), 1 ) . '%';
return $single_variation->get_price_html()."<input type='hidden' name='hidden_price' class='hidden_price' value='".$price."'>" . sprintf( __('<span class="pvt-discount-text"> You Saved: %s</span>', 'woocommerce' ), $saving_percentage );
}
return $single_variation->get_price_html()."<input type='hidden' name='hidden_price' class='hidden_price' value='".$price."'>";
}
add_filter( 'pvtfw_price_html', 'pvt_get_price_html_with_discount', 20, 2 );
}
// Variation Table support for Divi Theme (PVT Version 1.4.0+)
function pvt_divi_builder_support(){
$pvtfw_table = PVTFW_TABLE::instance();
$pvtfw_print_table = PVTFW_PRINT_TABLE::instance();
$table = $pvtfw_print_table::allocation();
remove_action('template_redirect', array( $pvtfw_table, 'remove_add_to_cart'), 29 );
remove_action($table['place'], array($pvtfw_print_table, 'print_table'), $table['priority']);
}
add_action('init', 'pvt_divi_builder_support');
// Keep 0 in quantity field (PVT Version 1.4.0+) will work with 1.4.5
add_filter('pvtfw_ajax_cart_prepare_quantity', function(){
return 0;
});
add_filter('woocommerce_quantity_input_min', function(){
return 0;
});
add_filter('pvtfw_qtyargs_input_value', function(){
return 0;
});
add_filter('pvtfw_cart_redirect_url', function($url){
if( is_product() ){
$product = wc_get_product( get_the_ID() );
$url = $product->get_permalink();
return $url;
}
}, 10);
// Remove Table title (Available Options)
add_filter('pvtfw_variant_table_varaints_heading', '__return_false');
function pvtbc_bulk_cart_init(){
if( !class_exists('PVTFW_TABLE_PRO' )){
return;
}
// Removing the Bulk Cart button from the table top
remove_action('pvtfw_variation_table_before', 'pvtfw_table_top_part', 99);
// Adding the Bulk Cart after the table
add_action('pvtfw_variation_table_after', 'pvtfw_table_top_part', 99);
// Changing the Bulk Cart Text
function pvt_bulk_cart_text_override(){
return _x( 'Add to Cart', 'Bulk Cart: Button Text', 'product-variant-table-for-woocommerce-pro' );
}
add_filter('pvtfw_table_bulk_cart_text', 'pvt_bulk_cart_text_override');
}
add_action( 'plugins_loaded', 'pvtbc_bulk_cart_init' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment