Commit e33eaf50 authored by Franco nextime Lanza's avatar Franco nextime Lanza

Now you can choose options in archive page

parent e73be9d2
......@@ -5,5 +5,8 @@ Fork of woothemes product addons plugin
Changes from the original addon:
* Show options also in archive and let add to cart directly from here
* Removed auto-update
* let's the first option added in select type be the default selected
......@@ -25,3 +25,40 @@ dl.product-addon-totals dd {
display: none;
color: red;
}
div.product-addon {
margin: 0 0;
}
div.product-addon p {
margin: 0 0;
margin-bottom: 7px;
}
div.product-addon h3.addon-name {
padding: 0 !important;
}
h3.addon-name {
margin: 0;
}
dl.product-addon-totals dt {
width:50%;
float: left;
}
.ddtotal {
font-size: 19px;
color: rgb(45, 126, 230);
}
.dttotal {
font-size: 19px;
}
.buttons_added {
max-width: 50%;
float: left;
}
......@@ -32,7 +32,7 @@ jQuery(document).ready(function($) {
$('.variations_form').on('found_variation', function( event, variation ) {
var $variation_form = $(this);
var $totals = $variation_form.find('#product-addons-total');
var $totals = $variation_form.find('[data-total=product-addons-total]');
if ( $( variation.price_html ).find('.amount:last').size() ) {
product_price = $( variation.price_html ).find('.amount:last').text();
......@@ -49,7 +49,7 @@ jQuery(document).ready(function($) {
$('.cart').bind( 'woocommerce-product-addons-update', function() {
var total = 0;
var $cart = $(this);
var $totals = $cart.find('#product-addons-total');
var $totals = $cart.find('[data-total=product-addons-total]');
var product_price = $totals.data( 'price' );
var product_type = $totals.data( 'type' );
......@@ -93,6 +93,9 @@ jQuery(document).ready(function($) {
var qty = parseFloat( $cart.find('input.qty').val() );
console.debug(qty);
console.debug(total);
qty=1;
if ( total > 0 && qty > 0 ) {
total = parseFloat( total * qty );
......@@ -121,17 +124,17 @@ jQuery(document).ready(function($) {
html = '<dl class="product-addon-totals"><dt>' + woocommerce_addons_params.i18n_addon_total + '</dt><dd><strong><span class="amount">' + formatted_addon_total + '</span></strong></dd>';
if ( formatted_grand_total ) {
html = html + '<dt>' + woocommerce_addons_params.i18n_grand_total + '</dt><dd><strong><span class="amount">' + formatted_grand_total + '</span></strong></dd>';
html = html + '<dt class="dttotal"><strong>' + woocommerce_addons_params.i18n_grand_total + '</strong></dt><dd class="ddtotal"><strong><span class="amount">' + formatted_grand_total + '</span></strong></dd>';
}
html = html + '</dl>';
$totals.html( html );
console.debug(html);
} else {
$totals.empty();
console.debug('empty');
}
$('body').trigger('updated_addons');
} );
......
......@@ -19,8 +19,12 @@ class Product_Addon_Display {
add_action( 'get_header', array( $this, 'styles' ) );
add_action( 'wc_quick_view_enqueue_scripts', array( $this, 'addon_scripts' ) );
// Addon display
// Addon display on single product page
add_action( 'woocommerce_before_add_to_cart_button', array( $this, 'display' ), 10 );
// Addon display on archive
//add_action( 'woocommerce_after_shop_loop_item', array( $this, 'display' ), 10 );
add_action( 'woocommerce_after_add_to_cart_button', array( $this, 'wc_closeform' ), 10 );
add_action( 'wc_product_addons_end', array( $this, 'totals' ), 10 );
// Change buttons/cart urls
......@@ -30,6 +34,14 @@ class Product_Addon_Display {
add_filter( 'woocommerce_product_add_to_cart_url', array( $this, 'add_to_cart_url' ), 10, 1 );
}
/**
* close the form after add to cart button
*/
function wc_closeform() {
if(!is_product())
echo '</form>';
}
/**
* styles function.
*
......@@ -52,6 +64,10 @@ class Product_Addon_Display {
* Enqueue addon scripts
*/
function addon_scripts() {
wp_register_style( 'woocommerce-better-addons', plugins_url( basename( dirname( dirname( __FILE__ ) ) ) ) . '/assets/css/frontend.css', '', '0.3.2' );
wp_enqueue_style( 'woocommerce-better-addons' );
wp_register_script( 'accounting', plugins_url( basename( dirname( dirname( __FILE__ ) ) ) ) . '/assets/js/accounting.js', '', '0.3.2' );
wp_enqueue_script( 'woocommerce-addons', plugins_url( basename( dirname( dirname( __FILE__ ) ) ) ) . '/assets/js/addons.js', array( 'jquery', 'accounting' ), '1.0', true );
......@@ -113,6 +129,9 @@ class Product_Addon_Display {
if ( is_array( $product_addons ) && sizeof( $product_addons ) > 0 ) {
if(!is_product())
echo '<form class="cart">';
do_action( 'wc_product_addons_start', $post_id );
foreach ( $product_addons as $addon ) {
......@@ -136,6 +155,8 @@ class Product_Addon_Display {
}
do_action( 'wc_product_addons_end', $post_id );
//if(!is_product())
// echo "</form>";
}
}
......@@ -154,7 +175,7 @@ class Product_Addon_Display {
else
$the_product = $product;
echo '<div id="product-addons-total" data-type="' . $the_product->product_type . '" data-price="' . ( is_object( $the_product ) ? $the_product->get_price() : '' ) . '"></div>';
echo '<div data-addons-pid="'.$the_product->id.'" data-total="product-addons-total" data-type="' . $the_product->product_type . '" data-price="' . ( is_object( $the_product ) ? $the_product->get_price() : '' ) . '"></div>';
}
/**
......@@ -286,7 +307,6 @@ class Product_Addon_Display {
*/
private function check_required_addons( $product_id ) {
$addons = get_product_addons( $product_id );
if ( $addons && ! empty( $addons ) ) {
foreach ( $addons as $addon ) {
if ( '1' == $addon['required'] ) {
......@@ -307,14 +327,13 @@ class Product_Addon_Display {
*/
public function add_to_cart_text( $text ) {
global $product;
// XXX Remove it also from archive product!
if ( ! is_single( $product->id ) ) {
if ( $this->check_required_addons( $product->id ) ) {
$product->product_type = 'addons';
$text = apply_filters( 'addons_add_to_cart_text', __( 'Select options', 'wc_product_addons' ) );
}
}
return $text;
}
......@@ -327,7 +346,7 @@ class Product_Addon_Display {
*/
function add_to_cart_url( $url ) {
global $product;
// XXX Remove it also from archive product
if ( ! is_single( $product->id ) && in_array( $product->product_type, array( 'subscription', 'simple' ) ) && ( ! isset( $_GET['wc-api'] ) || $_GET['wc-api'] !== 'WC_Quick_View' ) ) {
if ( $this->check_required_addons( $product->id ) ) {
$product->product_type = 'addons';
......
......@@ -172,7 +172,17 @@ if ( is_woocommerce_active() ) {
);
register_taxonomy_for_object_type( 'product_cat', 'global_product_addon' );
}
function remove_woo_ajax_button() {
// replace the ajax button with the complete add to cart button with QTY
remove_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_loop_add_to_cart', 10);
add_action( 'woocommerce_after_shop_loop_item', 'woocommerce_template_single_add_to_cart', 1);
}
add_action( 'init', 'product_addons_post_types', 20 );
add_action('plugins_loaded','remove_woo_ajax_button');
}
......@@ -13,3 +13,4 @@ if ( ! function_exists( 'is_woocommerce_active' ) ) {
return WC_Dependencies::woocommerce_active_check();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment