Plugin Directory

Changeset 1679726


Ignore:
Timestamp:
06/16/2017 07:40:14 AM (9 years ago)
Author:
labschool
Message:

1.1.0

Location:
pixel-de-facebook-para-wocommerce/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pixel-de-facebook-para-wocommerce/trunk/fb-admin.php

    r1677321 r1679726  
    6161    add_settings_field('pfb_woo_ref', '','pfb_woo_conf_ref_input','fb_eventos','pfb_woo_main');
    6262    add_settings_field('pfb_woo_mon', '','pfb_woo_conf_mon_input','fb_eventos','pfb_woo_main');
     63    add_settings_field('pfb_woo_tax', '','pfb_woo_conf_tax_input','fb_eventos','pfb_woo_main');
    6364
    6465    add_settings_field('pfb_woo_vc_', '','pfb_woo_conf_vc_input','fb_eventos','pfb_woo_main');
     
    6667    add_settings_field('pfb_woo_ic_', '','pfb_woo_conf_ic_input','fb_eventos','pfb_woo_main');
    6768    add_settings_field('pfb_woo_pur', '','pfb_woo_conf_pur_input','fb_eventos','pfb_woo_main');
     69   
     70    add_settings_field('pfb_woo_vcs', '','pfb_woo_conf_vcs_input','fb_eventos','pfb_woo_main');
     71    add_settings_field('pfb_woo_vca', '','pfb_woo_conf_vca_input','fb_eventos','pfb_woo_main');
     72    add_settings_field('pfb_woo_vct', '','pfb_woo_conf_vct_input','fb_eventos','pfb_woo_main');
    6873}
    6974
     
    99104    echo "<div id='col1'><label><strong>Identificador de producto</strong></label>
    100105          <div class='instruccion'>Puedes identificar la referencia del producto mediante el ID de Wordpress o el SKU que hayas definido.</div></div>";
    101     echo "<div id='col2'><select name='pfb_woo_options[product_ref]'><option value='1' " . selected( $id , 1,false) . ">ID Producto</option><option value='0' " . selected( $id , 0,false) . ">SKU</option></div>";
     106    echo "<div id='col2'><select name='pfb_woo_options[product_ref]'>
     107                <option value='1' " . selected( $id , 1,false) . ">ID Producto</option>
     108                <option value='0' " . selected( $id , 0,false) . ">SKU</option>
     109          </div>";
    102110}
    103111
     
    109117          <div class='instruccion'>La divisa debe coincidir con la que hayas configurado en Woocommerce seg&uacute;n norma ISO 4217.</div></div>";
    110118    echo "<div id='col2'><select name='pfb_woo_options[currency]'>
    111                             <option value='EUR' " . selected( $id , 'EUR',false) . ">EUR</option>
    112                             <option value='GBP' " . selected( $id , 'GBP',false) . ">GBP</option>
    113                             <option value='USD' " . selected( $id , 'USD',false) . ">USD</option>
    114                             </div>";
    115 }
     119                <option value='EUR' " . selected( $id , 'EUR',false) . ">EUR</option>
     120                <option value='GBP' " . selected( $id , 'GBP',false) . ">GBP</option>
     121                <option value='USD' " . selected( $id , 'USD',false) . ">USD</option>
     122          </div>";
     123}
     124
     125/* IMPUESTOS */
     126function pfb_woo_conf_tax_input() {
     127    $options = get_option('pfb_woo_options');
     128    $id = $options['taxes'];
     129    echo "<div id='col1'><label><strong>Aplicar impuestos</strong></label>
     130          <div class='instruccion'>Incluye los impuestos sobre los precios recogidos en los diferentes eventos activados.</div></div>";
     131    echo "<div id='col2'><input name='pfb_woo_options[taxes]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></div>";
     132}
     133
    116134
    117135/* EVENTO VIEWCONTENT */
     
    119137    $options = get_option('pfb_woo_options');
    120138    $id = $options['view_content'];
    121     echo "<div id='col3'>Configuraci&oacute;n de Eventos</div>";
     139    echo "<div id='col3'>Eventos Est&aacute;ndar</div>";
    122140    echo "<div id='col1'><label><strong>ViewContent</strong></label>
    123141          <div class='instruccion'>Incluye el evento 'ViewContent' cada vez que se carga una p&aacute;gina de producto.</div></div>";
     
    152170}
    153171
     172/* EVENTO VIEWSHOP */
     173function pfb_woo_conf_vcs_input() {
     174    $options = get_option('pfb_woo_options');
     175    $id = $options['view_shop'];
     176    echo "<div id='col3'>Eventos Personalizados</div>";
     177    echo "<div id='col1'><label><strong>ViewShop</strong></label>
     178          <div class='instruccion'>Incluye el evento personalizado 'ViewShop' cada vez que se carga una p&aacute;gina del cat&aacute;logo de productos.</div></div>";
     179    echo "<div id='col2'><input name='pfb_woo_options[view_shop]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></div>";
     180}
     181
     182/* EVENTO VIEWCATEGORY */
     183function pfb_woo_conf_vca_input() {
     184    $options = get_option('pfb_woo_options');
     185    $id = $options['view_category'];
     186    echo "<div id='col1'><label><strong>ViewCategory</strong></label>
     187          <div class='instruccion'>Incluye el evento personalizado 'ViewCategory' cada vez que se carga una p&aacute;gina de categor&iacute;a de productos.</div></div>";
     188    echo "<div id='col2'><input name='pfb_woo_options[view_category]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></div>";
     189}
     190
     191/* EVENTO VIEWTAG */
     192function pfb_woo_conf_vct_input() {
     193    $options = get_option('pfb_woo_options');
     194    $id = $options['view_tag'];
     195    echo "<div id='col1'><label><strong>ViewTag</strong></label>
     196          <div class='instruccion'>Incluye el evento personalizado 'ViewTag' cada vez que se carga una p&aacute;gina de etiqueta de productos.</div></div>";
     197    echo "<div id='col2'><input name='pfb_woo_options[view_tag]' type='checkbox' value='1' " . checked( $id , 1,false) . " /></div>";
     198}
    154199
    155200/* GUARDAR OPCIONES */
     
    161206    $updated['product_ref'] = $form['product_ref'];
    162207    $updated['currency'] = $form['currency'];
     208    $updated['taxes'] = $form['taxes'];
    163209    $updated['view_content'] = $form['view_content'];
     210    $updated['view_shop'] = $form['view_shop'];
     211    $updated['view_category'] = $form['view_category'];
     212    $updated['view_tag'] = $form['view_tag'];
    164213    $updated['add_to_cart'] = $form['add_to_cart'];
    165214    $updated['initiate_checkout'] = $form['initiate_checkout'];
  • pixel-de-facebook-para-wocommerce/trunk/fb-conf.php

    r1677321 r1679726  
    33Plugin Name: Pixel de Facebook para Woocommerce
    44Plugin URI: https://www.labschool.es
    5 Description: Agrega f&aacute;cilmente el p&iacute;xel de Facebook y los eventos de producto a tu tienda online con Woocommerce (ViewContent, AddToCart, InitiateCheckout y Purchase).
    6 Version: 1.0.7
     5Description: Agrega f&aacute;cilmente el pixel de Facebook, adem&aacute;s de eventos est&aacute;ndar y personalizados a tu Woocommerce (ViewShop, ViewCategory, ViewTag, ViewContent, AddToCart, InitiateCheckout y Purchase).
     6Version: 1.1.0
    77Author: Lab School
    88Author URI: https://www.labschool.es
     
    1414
    1515
    16 /* ACTIVAR PLUGIN */
     16// ACTIVAR PLUGIN
    1717register_activation_hook( __FILE__, 'pfb_woo_install' );
    1818
     
    2323        'product_ref'       => '1',
    2424        'currency'          => 'EUR',
     25        'taxes'             => '0',
    2526        'view_content'      => '0',
     27        'view_shop'         => '0',
     28        'view_category'     => '0',
     29        'view_tag'          => '0',
    2630        'add_to_cart'       => '0',
    2731        'initiate_checkout' => '0',
     
    3337}
    3438
    35 /* INICIAR PLUGIN */
     39// INICIAR PLUGIN
    3640add_action( 'plugins_loaded', 'pfb_woo_setup');
    37 function pfb_woo_setup() {add_action( 'wp_head', 'pfb_woo_header', 102 );}
     41function pfb_woo_setup() {
     42    add_action( 'wp_head', 'pfb_woo_header', 102 );
     43}
     44
    3845function pfb_woo_header() {
    3946    $options = get_option('pfb_woo_options');
     
    6471           
    6572            if( is_product() ){
    66                 $options = get_option('pfb_woo_options');
    67                 $content_sku = $product->get_sku();
    68                 $content_id = $product->get_id();
    69                 $name = $product->get_title();
     73                $options            = get_option('pfb_woo_options');
     74                $content_sku        = $product->get_sku();
     75                $content_id         = $product->get_id();
     76                $name               = $product->get_title();
     77                $price              = $product->get_price();
     78                $price_ex           = wc_get_price_excluding_tax($product);
     79                $product_cats       = get_the_terms( $product->get_id(), 'product_cat' );
     80                if ($product_cats) {
     81                    $cat = $product_cats[0];
     82                }       
    7083?>
    7184<!-- Facebook ViewContent event -->
    7285<script>
    7386fbq('track', 'ViewContent', {
    74     content_type:   'product',
    75     content_name:   '<?php echo $name ?>',
    76     content_ids:    ['<?php echo (isset($options['product_ref']) && $options['product_ref']) ? $content_id : $content_sku; ?>']
     87    content_type: 'product',
     88    content_name: '<?php echo $name ?>',
     89    content_category: '<?php echo $cat->name; ?>',
     90    content_ids:    ['<?php echo (isset($options['product_ref']) && $options['product_ref']) ? $content_id : $content_sku; ?>'],
     91    value: <?php echo (isset($options['taxes']) && $options['taxes']) ? $price : $price_ex; ?>,
     92    currency:'<?php echo $options['currency'];?>'
     93});
     94</script>
     95<?php
     96            }
     97        }
     98    }
     99   
     100    //VIEWSHOP
     101    if (!isset($options['view_shop']) != '1' || $options['view_shop'] ) {
     102        add_action( 'wp_footer', 'fb_viewshop' );
     103        function fb_viewshop() {           
     104            global $wp_query;
     105           
     106            if( is_shop() ){
     107                $options                = get_option('pfb_woo_options');
     108                $products               = array_values(array_map(function($item) {return wc_get_product($item->ID);}, $wp_query->get_posts()));
     109                foreach ($products as $product) {       
     110                    $content_sku[]      = "'".$product->get_sku()."'";
     111                    $content_id[]       = "'".$product->get_id()."'";
     112                }   
     113?>
     114<!-- Facebook ViewShop custom event -->
     115<script>
     116fbq('track', 'ViewShop', {
     117    content_type: 'product',
     118    content_ids: [<?php echo (isset($options['product_ref']) && $options['product_ref']) ? implode( ', ',$content_id) : implode( ', ',$content_sku); ?>]
     119});
     120</script>
     121<?php
     122            }
     123        }
     124    }
     125   
     126    //VIEWCATEGORY
     127    if (!isset($options['view_category']) != '1' || $options['view_category'] ) {
     128        add_action( 'wp_footer', 'fb_viewcategory' );
     129        function fb_viewcategory() {           
     130            global $wp_query;
     131           
     132            if( is_product_category() ){
     133                $options                = get_option('pfb_woo_options');
     134                $products               = array_values(array_map(function($item) {return wc_get_product($item->ID);}, $wp_query->get_posts()));
     135                foreach ($products as $product) {       
     136                    $content_sku[]      = "'".$product->get_sku()."'";
     137                    $content_id[]       = "'".$product->get_id()."'";
     138                }   
     139?>
     140<!-- Facebook ViewCategory custom event -->
     141<script>
     142fbq('track', 'ViewCategory', {
     143    content_type: 'product',
     144    content_category: '<?php echo single_cat_title(); ?>',
     145    content_ids: [<?php echo (isset($options['product_ref']) && $options['product_ref']) ? implode( ', ',$content_id) : implode( ', ',$content_sku); ?>]
     146});
     147</script>
     148<?php
     149            }
     150        }
     151    }
     152   
     153    //VIEWTAG
     154    if (!isset($options['view_tag']) != '1' || $options['view_tag'] ) {
     155        add_action( 'wp_footer', 'fb_viewtag' );
     156        function fb_viewtag() {         
     157            global $wp_query;
     158           
     159            if( is_product_tag() ){
     160                $options                = get_option('pfb_woo_options');
     161                $products               = array_values(array_map(function($item) {return wc_get_product($item->ID);}, $wp_query->get_posts()));
     162                foreach ($products as $product) {       
     163                    $content_sku[]      = "'".$product->get_sku()."'";
     164                    $content_id[]       = "'".$product->get_id()."'";
     165                }   
     166?>
     167<!-- Facebook ViewTag custom event -->
     168<script>
     169fbq('track', 'ViewTag', {
     170    content_type: 'product',
     171    content_category: '<?php echo single_tag_title(); ?>',
     172    content_ids: [<?php echo (isset($options['product_ref']) && $options['product_ref']) ? implode( ', ',$content_id) : implode( ', ',$content_sku); ?>]
    77173});
    78174</script>
     
    87183        function fb_addtocart( ) {
    88184           
    89             if( is_cart() ){       
    90                 $options = get_option('pfb_woo_options');
    91                 $cart_items = WC()->cart->cart_contents;
    92                 $cart_total = WC()->cart->subtotal_ex_tax;
    93                 $cart_prods = WC()->cart->get_cart();
     185            if( is_cart() && WC()->cart->get_cart_contents_count() > 0){       
     186                $options            = get_option('pfb_woo_options');
     187                $cart_items         = WC()->cart->cart_contents;
     188                $cart_total_ex      = WC()->cart->subtotal_ex_tax;
     189                $cart_total         = WC()->cart->subtotal;
     190                $cart_prods         = WC()->cart->get_cart();
    94191               
    95192                if($cart_items) foreach ($cart_items as $cart_item){
    96                     $content_id[] = "'".$cart_item['product_id']."'";
    97                     $content_sku[] = "'".$cart_item['data']->get_sku()."'";
     193                    $content_id[]   = "'".$cart_item['product_id']."'";
     194                    $content_sku[]  = "'".$cart_item['data']->get_sku()."'";
    98195                }               
    99196?>
     
    103200    content_type: 'product',
    104201    content_ids: [<?php echo (isset($options['product_ref']) && $options['product_ref']) ? implode( ', ',$content_id) : implode( ', ',$content_sku); ?>],
    105     value: <?php echo $cart_total ?>,
     202    value: <?php echo (isset($options['taxes']) && $options['taxes']) ? $cart_total : $cart_total_ex; ?>,
    106203    currency:'<?php echo $options['currency'];?>'
    107204});
     
    118215       
    119216            if( is_checkout() ){
    120                 $options = get_option('pfb_woo_options');
    121                 $cart_items = WC()->cart->cart_contents;
    122                 $cart_total = WC()->cart->subtotal_ex_tax;
    123                 $cart_prods = WC()->cart->get_cart();
     217                $options            = get_option('pfb_woo_options');
     218                $cart_items         = WC()->cart->cart_contents;
     219                $cart_total_ex      = WC()->cart->subtotal_ex_tax;
     220                $cart_total         = WC()->cart->subtotal;
     221                $cart_prods         = WC()->cart->get_cart();
    124222               
    125223                if($cart_items) foreach ($cart_items as $cart_item){
    126                     $content_id[] = "'".$cart_item['product_id']."'";
    127                     $content_sku[] = "'".$cart_item['data']->get_sku()."'";
     224                    $content_id[]   = "'".$cart_item['product_id']."'";
     225                    $content_sku[]  = "'".$cart_item['data']->get_sku()."'";
    128226                }   
    129227?>
     
    133231    content_type: 'product',
    134232    content_ids: [<?php echo (isset($options['product_ref']) && $options['product_ref']) ? implode( ', ',$content_id) : implode( ', ',$content_sku); ?>],
    135     value: <?php echo $cart_total ?>,
     233    value: <?php echo (isset($options['taxes']) && $options['taxes']) ? $cart_total : $cart_total_ex; ?>,
    136234    currency:'<?php echo $options['currency'];?>'
    137235});
     
    146244        add_action( 'woocommerce_thankyou', 'fb_purchase' );
    147245        function fb_purchase( $order_id ) {
    148            
    149             $options = get_option('pfb_woo_options');
    150             $order = new WC_Order( $order_id );
    151             $order_total = $order->get_total();
    152             $order_items = $order->get_items();         
     246
     247            $options                = get_option('pfb_woo_options');
     248            $order                  = new WC_Order( $order_id );
     249            $order_total            = $order->get_total();
     250            $order_total_ex         = $order_total - $order->get_total_tax();
     251            $order_items            = $order->get_items();         
    153252           
    154253            if($order_items) foreach ($order_items as $order_item => $item){
    155                 $content_id[] = "'".$item['product_id']."'";
    156                 $content_sku[] = "'".$item->get_product()->get_sku()."'";               
     254                $content_id[]       = "'".$item['product_id']."'";
     255                $product_id         = wc_get_product($item['product_id']);
     256                $variation_id       = wc_get_product($item['variation_id']);
     257                if ($variation_id) {
     258                    $content_sku[]  = "'".$variation_id->get_sku()."'";
     259                } else {
     260                    $content_sku[]  = "'".$product_id->get_sku()."'";
     261                }
    157262            }   
    158263?>
     
    162267    content_type: 'product',
    163268    content_ids: [<?php echo (isset($options['product_ref']) && $options['product_ref']) ? implode( ', ',$content_id) : implode( ', ',$content_sku); ?>],
    164     value: <?php echo $order_total ?>,
     269    value: <?php echo (isset($options['taxes']) && $options['taxes']) ? $order_total : $order_total_ex; ?>,
    165270    currency:'<?php echo $options['currency'];?>'
    166271});
    167272</script>
    168273<?php
    169             }
     274        }
    170275    }
    171276}
  • pixel-de-facebook-para-wocommerce/trunk/readme.txt

    r1677321 r1679726  
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1010
    11 Agrega fácilmente el pixel de Facebook y los eventos de producto a tu Woocommerce (ViewContent, AddToCart, InitiateCheckout y Purchase).
     11Agrega fácilmente el pixel de Facebook, además de eventos estándar y personalizados a tu Woocommerce (ViewShop, ViewCategory, ViewTag, ViewContent, AddToCart, InitiateCheckout y Purchase).
    1212
    1313== Description ==
    1414
    15 Inserta de forma rápida y sencilla el pixel de Facebook y los eventos principales de producto (ViewContent, AddToCart, InitiateCheckout y Purchase) a tu Woocommerce.
     15Inserta de forma rápida y sencilla el pixel de Facebook y los eventos estándar de tienda online (ViewContent, AddToCart, InitiateCheckout y Purchase) a tu Woocommerce, además de otros eventos personalizados de la tienda online (ViewShop, ViewCategory y ViewTag)
    1616
    1717= Características =
     
    1919* Sencillo y fácil de configurar, en apenas unos segundos.
    2020* Posibilidad de elegir entre ID de producto o SKU.
     21* Posibilidad de activar/desactivar los impuestos para el seguimiento del pixel.
    2122* Posibilidad de activar/desactivar cada tipo de evento según la configuración de tu tienda online.
    2223* Ocupa menos de 20 Kb para interferir al mínimo en el rendimiento de tu web.
     
    3839
    3940== Changelog ==
     41
     42= Version 1.1.0 =
     43Disponible 16/06/2017
     44
     45- Agregar eventos personalizados a las páginas de Woocommerce (ViewShop, ViewCategory y ViewTag).
     46- Posibilidad de activar/desactivar los impuestos para el seguimiento del pixel.
     47- Solucionados errores menores.
    4048
    4149= Version 1.0.4 =
Note: See TracChangeset for help on using the changeset viewer.