Changeset 1679726
- Timestamp:
- 06/16/2017 07:40:14 AM (9 years ago)
- Location:
- pixel-de-facebook-para-wocommerce/trunk
- Files:
-
- 3 edited
-
fb-admin.php (modified) (7 diffs)
-
fb-conf.php (modified) (11 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pixel-de-facebook-para-wocommerce/trunk/fb-admin.php
r1677321 r1679726 61 61 add_settings_field('pfb_woo_ref', '','pfb_woo_conf_ref_input','fb_eventos','pfb_woo_main'); 62 62 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'); 63 64 64 65 add_settings_field('pfb_woo_vc_', '','pfb_woo_conf_vc_input','fb_eventos','pfb_woo_main'); … … 66 67 add_settings_field('pfb_woo_ic_', '','pfb_woo_conf_ic_input','fb_eventos','pfb_woo_main'); 67 68 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'); 68 73 } 69 74 … … 99 104 echo "<div id='col1'><label><strong>Identificador de producto</strong></label> 100 105 <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>"; 102 110 } 103 111 … … 109 117 <div class='instruccion'>La divisa debe coincidir con la que hayas configurado en Woocommerce según norma ISO 4217.</div></div>"; 110 118 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 */ 126 function 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 116 134 117 135 /* EVENTO VIEWCONTENT */ … … 119 137 $options = get_option('pfb_woo_options'); 120 138 $id = $options['view_content']; 121 echo "<div id='col3'> Configuración de Eventos</div>";139 echo "<div id='col3'>Eventos Estándar</div>"; 122 140 echo "<div id='col1'><label><strong>ViewContent</strong></label> 123 141 <div class='instruccion'>Incluye el evento 'ViewContent' cada vez que se carga una página de producto.</div></div>"; … … 152 170 } 153 171 172 /* EVENTO VIEWSHOP */ 173 function 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ágina del catá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 */ 183 function 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ágina de categorí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 */ 192 function 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á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 } 154 199 155 200 /* GUARDAR OPCIONES */ … … 161 206 $updated['product_ref'] = $form['product_ref']; 162 207 $updated['currency'] = $form['currency']; 208 $updated['taxes'] = $form['taxes']; 163 209 $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']; 164 213 $updated['add_to_cart'] = $form['add_to_cart']; 165 214 $updated['initiate_checkout'] = $form['initiate_checkout']; -
pixel-de-facebook-para-wocommerce/trunk/fb-conf.php
r1677321 r1679726 3 3 Plugin Name: Pixel de Facebook para Woocommerce 4 4 Plugin URI: https://www.labschool.es 5 Description: Agrega fácilmente el p íxel de Facebook y los eventos de producto a tu tienda online con Woocommerce (ViewContent, AddToCart, InitiateCheckout y Purchase).6 Version: 1. 0.75 Description: Agrega 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). 6 Version: 1.1.0 7 7 Author: Lab School 8 8 Author URI: https://www.labschool.es … … 14 14 15 15 16 / * ACTIVAR PLUGIN */16 // ACTIVAR PLUGIN 17 17 register_activation_hook( __FILE__, 'pfb_woo_install' ); 18 18 … … 23 23 'product_ref' => '1', 24 24 'currency' => 'EUR', 25 'taxes' => '0', 25 26 'view_content' => '0', 27 'view_shop' => '0', 28 'view_category' => '0', 29 'view_tag' => '0', 26 30 'add_to_cart' => '0', 27 31 'initiate_checkout' => '0', … … 33 37 } 34 38 35 / * INICIAR PLUGIN */39 // INICIAR PLUGIN 36 40 add_action( 'plugins_loaded', 'pfb_woo_setup'); 37 function pfb_woo_setup() {add_action( 'wp_head', 'pfb_woo_header', 102 );} 41 function pfb_woo_setup() { 42 add_action( 'wp_head', 'pfb_woo_header', 102 ); 43 } 44 38 45 function pfb_woo_header() { 39 46 $options = get_option('pfb_woo_options'); … … 64 71 65 72 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 } 70 83 ?> 71 84 <!-- Facebook ViewContent event --> 72 85 <script> 73 86 fbq('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> 116 fbq('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> 142 fbq('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> 169 fbq('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); ?>] 77 173 }); 78 174 </script> … … 87 183 function fb_addtocart( ) { 88 184 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(); 94 191 95 192 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()."'"; 98 195 } 99 196 ?> … … 103 200 content_type: 'product', 104 201 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; ?>, 106 203 currency:'<?php echo $options['currency'];?>' 107 204 }); … … 118 215 119 216 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(); 124 222 125 223 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()."'"; 128 226 } 129 227 ?> … … 133 231 content_type: 'product', 134 232 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; ?>, 136 234 currency:'<?php echo $options['currency'];?>' 137 235 }); … … 146 244 add_action( 'woocommerce_thankyou', 'fb_purchase' ); 147 245 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(); 153 252 154 253 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 } 157 262 } 158 263 ?> … … 162 267 content_type: 'product', 163 268 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; ?>, 165 270 currency:'<?php echo $options['currency'];?>' 166 271 }); 167 272 </script> 168 273 <?php 169 }274 } 170 275 } 171 276 } -
pixel-de-facebook-para-wocommerce/trunk/readme.txt
r1677321 r1679726 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 10 10 11 Agrega fácilmente el pixel de Facebook y los eventos de producto a tu Woocommerce (ViewContent, AddToCart, InitiateCheckout y Purchase).11 Agrega 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). 12 12 13 13 == Description == 14 14 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.15 Inserta 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) 16 16 17 17 = Características = … … 19 19 * Sencillo y fácil de configurar, en apenas unos segundos. 20 20 * Posibilidad de elegir entre ID de producto o SKU. 21 * Posibilidad de activar/desactivar los impuestos para el seguimiento del pixel. 21 22 * Posibilidad de activar/desactivar cada tipo de evento según la configuración de tu tienda online. 22 23 * Ocupa menos de 20 Kb para interferir al mínimo en el rendimiento de tu web. … … 38 39 39 40 == Changelog == 41 42 = Version 1.1.0 = 43 Disponible 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. 40 48 41 49 = Version 1.0.4 =
Note: See TracChangeset
for help on using the changeset viewer.