Skip to content

Instantly share code, notes, and snippets.

@Astargh
Created February 22, 2017 22:41
Show Gist options
  • Save Astargh/21bc34ccc72ec763495fafc5947dfb25 to your computer and use it in GitHub Desktop.
Save Astargh/21bc34ccc72ec763495fafc5947dfb25 to your computer and use it in GitHub Desktop.
Quick view woocommerce
wp_enqueue_script( 'my-ajax-request', get_template_directory_uri() . '/js/main.js' );
wp_localize_script( 'my-ajax-request', 'myajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
add_action('wp_ajax_woo_quickview', 'woo_quickview');
add_action('wp_ajax_nopriv_woo_quickview', 'woo_quickview');
function woo_quickview() {
global $post, $product, $woocommerce;
$prod_id = $_POST["product"];
$post = get_post( $prod_id );
$product = get_product( $prod_id );
ob_start();
woocommerce_get_template( 'quickview.php');
$output = ob_get_contents();
ob_end_clean();
echo $output;
wp_die();
}
$('.quickview').click(function() {
var thisEl = $(this);
var product_id = $(this).attr('data-prod');
var data = {action: 'woo_quickview', product: product_id};
$.ajax({
url: myajax.ajaxurl,
type: "POST",
data: data,
beforeSend: function() {
this.addClass('loading');
},
success: function (response) {
$('.popup_item_cart').find('.popup_item_cart_block_left').find('.catalog_item').html(response);
/*$.magnificPopup.open({
mainClass: 'mfp-zoom',
items: {
src: '<div class="product-modal">'+response+'</div>',
type: 'inline'
}
});*/
setTimeout(function () {
/*$('.product-modal form').wc_variation_form();
$('.product-modal form select').change();*/
}, 500);
}
,
complete: function() {
this.removeClass('loading');
}
});
});
<?php
/**
* Created by PhpStorm.
* User: astargh
* Date: 14.02.17
* Time: 01:01
*/
global $product;?>
<?php
/**
* woocommerce_before_single_product hook.
*
* @hooked wc_print_notices - 10
*/
do_action( 'woocommerce_before_single_product' );
if ( post_password_required() ) {
echo get_the_password_form();
return;
}
?>
<div itemscope itemtype="<?php echo woocommerce_get_product_schema(); ?>" id="product-<?php the_ID(); ?>" <?php post_class(); ?>>
<div <?php post_class(); ?>>
<div style="min-height: 99px">
<?php
/**
* woocommerce_shop_loop_item_title hook.
*
* @hooked woocommerce_template_loop_product_title - 10
*/
do_action( 'woocommerce_shop_loop_item_title' ); ?>
</div>
<div class="catalog_item_size">
<?php
$metas = get_post_meta( $post->ID );
if ( isset( $metas['width'] ) && isset( $metas['height'] ) ) {
?>
<ul>
<li><?php echo get_post_meta( $post->ID, 'width', true ); ?> см</li>
<li><?php echo get_post_meta( $post->ID, 'height', true ); ?> см</li>
</ul>
<?php } ?>
</div>
<?php if( has_post_thumbnail() ) { ?>
<div class="catalog_item_thumb">
<?php /**
* woocommerce_before_shop_loop_item_title hook.
*
* @hooked woocommerce_show_product_loop_sale_flash - 10
* @hooked woocommerce_template_loop_product_thumbnail - 10
*/
do_action( 'woocommerce_before_shop_loop_item_title' ); ?>
<?php
if( isset($metas['share']) ) {
?>
<div class="ribbon">
<?php echo get_post_meta($post->ID, 'share', true); ?>
</div>
<?php
}
if( isset($metas['sale']) ) {
?>
<div class="ribbon">
<?php echo get_post_meta($post->ID, 'sale', true); ?>
</div>
<?php
}
if( isset($metas['new']) ) {
?>
<div class="ribbon">
<?php echo get_post_meta($post->ID, 'new', true); ?>
</div>
<?php
}
?>
</div>
<?php } ?>
<div class="options_size" style="font-size: 16px;">
<?php
$size = $product->get_attribute( 'pa_fl_size' );
global $product;
$size = array_values( wc_get_product_terms( $product->id, 'pa_fl_size', array( 'fields' => 'names') ) );
?>
</div>
<?php if( $size ) {
?>
<?php } else { ?>
<div class="catalog_item_empty"></div>
<?php } ?>
<div class="catalog_item_price">
<?php
/**
* ADD PRODUCT VARIABLE WITH ADD TO CART ON CATALOG PAGE
ADDED BY GW
**/
?>
<div class="catbox">
<?php
/**
* woocommerce_after_shop_loop_item_title hook
*
* @hooked woocommerce_template_loop_rating - 5
* @hooked woocommerce_template_loop_price - 10
*/
?>
<?php
//ADD VARIATIONS BEFORE ADD TO CART
if($product->product_type == "variable"){
woocommerce_variable_add_to_cart();
} else {
do_action( 'woocommerce_after_shop_loop_item_title' );
woocommerce_template_single_add_to_cart();
}
?>
</div>
</div>
<?php wp_reset_postdata(); ?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment