· 4 years ago · Jul 30, 2021, 07:26 PM
1File Manager
2 / wp-content / themes / woodmart
3Search
4 Upload
5 New Item
6 Thymochenko.Cabral
7
8Name Size Modified Perms Owner Actions
9 ..
10
11 css
12Folder 15.11.20 22:02 0755 www-data:www-data
13
14 fonts
15Folder 15.11.20 22:02 0755 www-data:www-data
16
17 header-elements
18Folder 15.11.20 22:02 0755 www-data:www-data
19
20 images
21Folder 15.11.20 22:02 0755 www-data:www-data
22
23 inc
24Folder 15.11.20 22:02 0755 www-data:www-data
25
26 js
27Folder 15.11.20 22:02 0755 www-data:www-data
28
29 languages
30Folder 15.11.20 22:02 0755 www-data:www-data
31
32 vc_templates
33Folder 15.11.20 22:02 0755 www-data:www-data
34
35 woocommerce
36Folder 01.07.21 20:15 0755 www-data:www-data
37
38 404.php
39683 B 15.11.20 22:02 0745 www-data:www-data
40
41 archive-portfolio.php
42105 B 15.11.20 22:02 0745 www-data:www-data
43
44 author-bio.php
451.11 KB 15.11.20 22:02 0745 www-data:www-data
46
47 comments.php
481.89 KB 15.11.20 22:02 0745 www-data:www-data
49
50 content-none.php
51518 B 15.11.20 22:02 0745 www-data:www-data
52
53 content-portfolio-slider.php
542.04 KB 15.11.20 22:02 0745 www-data:www-data
55
56 content-portfolio.php
572.99 KB 15.11.20 22:02 0745 www-data:www-data
58
59 content-slider.php
602.4 KB 15.11.20 22:02 0745 www-data:www-data
61
62 content.php
637.34 KB 15.11.20 22:02 0745 www-data:www-data
64
65 Documentos.php
661.2 KB 15.11.20 22:02 0745 www-data:www-data
67
68 footer.php
693.91 KB 05.05.21 17:35 0745 www-data:www-data
70
71 functions.php
7216.59 KB 15.11.20 22:02 0745 www-data:www-data
73
74 header.php
755.32 KB 01.07.21 23:49 0745 www-data:www-data
76
77 index.php
78447 B 15.11.20 22:02 0745 www-data:www-data
79
80 Lojista.php
81131 B 15.11.20 22:02 0745 www-data:www-data
82
83 maintenance.php
84429 B 15.11.20 22:02 0745 www-data:www-data
85
86 page.php
871.3 KB 15.11.20 22:02 0745 www-data:www-data
88
89 portfolio.php
90152 B 15.11.20 22:02 0745 www-data:www-data
91
92 reordering_fields_checkout_functions.php
9343.81 KB 18.06.21 16:20 0745 www-data:www-data
94
95 screenshot.png
96139.99 KB 15.11.20 22:02 0745 www-data:www-data
97
98 searchform.php
9987 B 15.11.20 22:02 0745 www-data:www-data
100
101 sidebar-footer.php
1021.13 KB 15.11.20 22:02 0745 www-data:www-data
103
104 sidebar.php
105951 B 15.11.20 22:02 0745 www-data:www-data
106
107 single-portfolio.php
1081.3 KB 15.11.20 22:02 0745 www-data:www-data
109
110 single.php
1112 KB 15.11.20 22:02 0745 www-data:www-data
112
113 stable.footer.php
1143.39 KB 09.12.20 21:06 0745 www-data:www-data
115
116 stable.header.php
1174.3 KB 25.11.20 14:21 0644 www-data:www-data
118
119 stable.reordering_fields_checkout_functions.php
12040.27 KB 02.02.21 13:41 0644 www-data:www-data
121
122 style.css
1231.06 MB 15.11.20 22:02 0745 www-data:www-data
124
125 style.min.css
126902.08 KB 15.11.20 22:02 0745 www-data:www-data
127
128 taxonomy-project-cat.php
129114 B 15.11.20 22:02 0745 www-data:www-data
130
131 Varejista.php
132129 B 15.11.20 22:02 0745 www-data:www-data
133
134 wpml-config.xml
1358.19 KB 15.11.20 22:02 0745 www-data:www-data
136Full Size: 2.23 MB File: 33 Folder: 9 Memory used: 2 MB Partition size: 30.46 GB free of 38.71 GB
137
138Tiny File Manager 2.4.3
139reordering_fields_checkout_functions.php
140×
141<?php
142
143add_filter( 'woocommerce_sale_flash', 'wooc_custom_replace_sale_text',99,3);
144function wooc_custom_replace_sale_text( $html,$post, $product) {
145 print_r($html);
146 return str_replace( __( 'Sale!', 'woocommerce' ), __( 'Your Text', 'woocommerce' ), $html );
147}
148
149
150add_filter( "woocommerce_checkout_fields", "reordering_custom_default_email_field", 15, 1 );
151
152function reordering_custom_default_email_field($fields){
153 $fields['billing']['billing_email']['priority'] = 1;
154 return $fields;
155}
156
157$fields['billing']['billing_email']['priority'] = 10;
158
159add_filter( 'woocommerce_default_address_fields', 'custom_override_default_locale_fields' );
160function custom_override_default_locale_fields( $fields ) {
161 $fields['billing_first_name']['priority'] = 20;
162 $fields['billing_last_name']['priority'] = 30;
163 $fields['billing_persontype']['priority'] = 40;
164 $fields['billing_cpf']['priority'] = 50;
165 $fields['billing_country']['priority'] = 60;
166 $fields['billing_postcode']['priority'] = 70;
167 $fields['billing_company']['priority'] = 80;
168 $fields['billing_cnpj']['priority'] = 90;
169 $fields['billing_address_1']['priority'] = 100;
170 $fields['billing_number']['priority'] = 110;
171 $fields['billing_address_2']['priority'] = 120;
172 $fields['billing_neighborhood']['priority'] = 130;
173 $fields['billing_city']['priority'] = 140;
174 $fields['billing_state']['priority'] = 150;
175 $fields['billing_phone']['priority'] = 160;
176 $fields['billing_cellphone']['priority'] = 170;
177
178 return $fields;
179}
180
181function my_wc_custom_checkout_billing_fields($fields) {
182 $fields['billing_neighborhood']['required'] = true;
183
184 return $fields;
185}
186
187add_filter('woocommerce_billing_fields', 'my_wc_custom_checkout_billing_fields',20);
188/*
189add_filter( 'woocommerce_checkout_fields' , 'onblur_postcode' );
190function onblur_postcode( $fields ) {
191
192 $fields['billing']['billing_postcode']['onblur'] = 'onblur="pesquisacep(this.value);"';
193 return $fields;
194}*/
195
196
197
198 /**
199 * Regular user
200 */
201
202function my_account_menu_order() {
203 $menuOrder = array(
204 'dashboard' => __( 'Painel', 'woocommerce' ),
205 'orders' => __( 'Pedidos', 'woocommerce' ),
206 'edit-address' => __( 'Endereços', 'woocommerce' ),
207 'edit-account' => __( 'Detalhes da Conta', 'woocommerce' ),
208 'customer-logout' => __( 'Sair', 'woocommerce' ),
209 );
210 return $menuOrder;
211 }
212
213 add_filter ( 'woocommerce_account_menu_items', 'my_account_menu_order' );
214
215
216 /*
217 **
218 * Register new endpoints to use inside My Account page.
219 */
220
221$user = wp_get_current_user();
222$allowed_roles = array('subscriber', 'administrator');
223
224if( array_intersect($allowed_roles, $user->roles ) ) {
225
226
227 function my_account_menu_order_varej(){
228 $menuOrder = array(
229 'dashboard' => __( 'Painel', 'woocommerce' ),
230 'orders' => __( 'Pedidos', 'woocommerce' ),
231 'Lojista' => __( 'Produtos', 'woocommerce' ),
232 'Documentos' => __( 'Documentos', 'woocommerce' ),
233 'edit-address' => __( 'Endereços', 'woocommerce' ),
234 'edit-account' => __( 'Detalhes da Conta', 'woocommerce' ),
235 'customer-logout' => __( 'Sair', 'woocommerce' ),
236 );
237 return $menuOrder;
238 }
239
240add_filter ( 'woocommerce_account_menu_items', 'my_account_menu_order_varej' );
241
242//lembrar de atualizar os permalinks em configurações pois é necessários pois há cache do wp
243add_action( 'init', 'my_account_new_endpoints' );
244add_action( 'init', 'my_account_new_endpoints_documentos' );
245
246 function my_account_new_endpoints() {
247 flush_rewrite_rules();
248 add_rewrite_endpoint( 'Lojista', EP_ROOT | EP_PAGES );
249
250 }
251
252 function my_account_new_endpoints_documentos() {
253 flush_rewrite_rules();
254 add_rewrite_endpoint( 'Documentos', EP_ROOT | EP_PAGES );
255
256 }
257 /**
258 * Get new endpoint content
259 */
260
261 // Awards
262 add_action( 'woocommerce_account_Lojista_endpoint', 'Lojista_endpoint_content' );
263 function Lojista_endpoint_content() {
264 flush_rewrite_rules();
265 get_template_part('Lojista');
266 }
267
268
269 // Awards
270 add_action( 'woocommerce_account_Documentos_endpoint', 'Documentos_endpoint_content' );
271 function Documentos_endpoint_content() {
272 flush_rewrite_rules();
273 get_template_part('Documentos');
274 }
275}
276
277
278add_filter( 'get_terms', 'ts_get_subcategory_terms', 10, 3 );
279function ts_get_subcategory_terms($terms, $taxonomies, $args){
280 $user = wp_get_current_user();
281 $allowed_roles = array('subscriber', 'administrator');
282 $new_terms = array();
283 // if it is a product category and on the shop page
284 if (in_array('product_cat', $taxonomies) && ! is_admin() && is_shop()
285 && ! array_intersect($allowed_roles, $user->roles )) {
286 foreach( $terms as $key => $term ) {
287 if ( !in_array( $term->slug, array( 'lojista' ) ) ) { //pass the slug name here
288 $new_terms[] = $term;
289 }
290 }
291 $terms = $new_terms;
292 }
293 return $terms;
294 }
295
296
297add_shortcode ('BannerVarejista', 'banner_varejista_shortcode');
298
299function banner_varejista_shortcode($atts) {
300 $user = wp_get_current_user();
301 $allowed_roles = array('subscriber', 'administrator');
302 if(!array_intersect($allowed_roles, $user->roles)){
303 return false;
304 }
305 else{
306 echo do_shortcode('[rev_slider alias="banner-principal"]');
307 }
308
309}
310
311/**
312 * Add custom data to WC API shop order response
313 * Overriding "$object" here with $order so it's easier to access its properties
314 */
315/*function my_wc_rest_prepare_order( $response, $order, $request ) {
316 setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
317 date_default_timezone_set('America/Sao_Paulo');
318 $timecreated = strftime('%A, %d de %B de %Y', strtotime('today'));
319 if( empty( $response->data ) )
320 return $response;
321
322 $order_id = $order->get_id();
323
324 // Get an instance of the WC_Order object
325 $order = wc_get_order($order_id);
326
327 // Get the user ID from WC_Order methods
328 $user_id = $order->get_customer_id(); // $order->get_user_id(); // or $order->get_customer_id();
329
330 // check for WooCommerce Social Login User Avatar
331 if( class_exists( 'WC_Social_Login' ) ) {
332
333 $fb_avatar = get_user_meta( $user_id, '_wc_social_login_facebook_profile_image', true );
334 $gplus_avatar = get_user_meta( $user_id, '_wc_social_login_google_profile_image', true );
335
336 }
337
338 $social_data = array();
339 $avatar_url = array();
340
341 $customer_picture = array(
342 'default' => get_avatar_url( $user_id ),
343 'facebook' => ( $fb_avatar ) ? esc_url( $fb_avatar ) : '',
344 'google' => ( $gplus_avatar ) ? esc_url( $gplus_avatar ) : ''
345 );
346
347 if(is_rest()){
348 $response->data['meta_data'][0] = ['key'=>'user_rest_request', 'value'=>'ciro'];
349 $response->data['meta_data'][1] = ['key'=>'rest_modification_date', 'value'=>$timecreated];
350
351 }
352 return $response;
353}
354
355add_filter( 'woocommerce_rest_prepare_shop_order_object', 'my_wc_rest_prepare_order', 10, 3 );
356
357*/
358/*
359
360function your_prefix_on_insert_rest_api( $object, $request, $is_creating ) {
361 if ( ! $is_creating ) {
362 return;
363 }
364
365 $order_id = $object->get_id();
366 $wc_order = new WC_Order( $order_id );
367 $wc_order->update_status('awaiting-shipment');
368
369 do_action( 'woocommerce_new_order', $order_id, $wc_order );
370}
371
372add_action( "woocommerce_rest_insert_shop_order_object", 'your_prefix_on_insert_rest_api', 10, 3 );*/
373
374//sempre que um status for alterado | registra qual usuário efetuou a operação
375/*
376add_action('woocommerce_order_status_changed', 'order_confirmation',10, 1);
377function order_confirmation($order_id){
378
379 $wc_order = new WC_Order($order_id);
380 $wc_order->update_status('completed');
381 do_action( 'woocommerce_new_order', $order_id, $wc_order );
382 update_post_meta( $order_id, 'user_altered', sanitize_text_field('user_altered'));
383 error_log( print_r( 'Works???', true ) );
384}
385*/
386
387//add_action('woocommerce_new_order', 'order_confirmation',10,1);
388
389//sempre que um pedido for inserido | registra quem efetuou a operação
390
391//sempre que um pedido for alterado | registra quem efetuou a operação
392
393
394
395// define the woocommerce_api_create_order callback
396/*
397function action_woocommerce_api_create_order( $order_get_id, $data, $instance ) {
398 // make action magic happen here...
399 $wc_order = new WC_Order($order_id);
400 $wc_order->update_status('completed');
401 do_action( 'woocommerce_new_order', $order_id, $wc_order );
402 update_post_meta( $order_id, 'user_altered', sanitize_text_field('user_altered'));
403 error_log( print_r( 'Works???', true ) );
404}
405 */
406// add the action
407#add_action( 'woocommerce_api_create_order', 'action_woocommerce_api_create_order', 10, 3 );
408
409
410
411
412/*
413add_filter( 'rest_pre_echo_response', function( $response, $object, $request ) {
414 setlocale(LC_TIME, 'pt_BR', 'pt_BR.utf-8', 'pt_BR.utf-8', 'portuguese');
415 date_default_timezone_set('America/Sao_Paulo');
416 $timecreated = strftime('%A, %d de %B de %Y', strtotime('today'));
417
418 $order_id = $response['id'];
419 $wc_order = new WC_Order($order_id);
420 //$wc_order->set_order_key("1235481-XML");
421 if(!$wc_order->meta_exists('rest_admin_user') && !$wc_order->meta_exists('rest_modification_date')){
422 $wc_order->add_meta_data('rest_admin_user','Ciro');
423 $wc_order->add_meta_data('rest_modification_date',$timecreated);
424
425 }
426
427
428 //do_action( 'woocommerce_new_order', $order_id, $wc_order );
429 //update_post_meta( $order_id, 'user_altered', sanitize_text_field('user_altered'));
430 $wc_order->save();
431 //$wc_orderData->save();
432 //criamos o arquivo
433 //$arquivo = fopen('meuarquivo.txt','w');
434 //verificamos se foi criado
435 //if ($arquivo == false) die('Não foi possível criar o arquivo.');
436 //escrevemos no arquivo
437 //$texto = $response['id'] . " + " . $atualizou;
438 //fwrite($arquivo, $texto);
439 //Fechamos o arquivo após escrever nele
440 if(is_rest()){
441 $response->data['meta_data']['key'] = 'user_rest_request';
442 $response->data['meta_data']['value'] = 'Ciro';
443 $response->data['meta_data']['key'] = 'rest_modification_date';
444 $response->data['meta_data']['value'] = $timecreated;
445
446 }
447 //fclose($arquivo);
448 return $response;
449}, 10, 3 );
450
451*/
452
453
454add_filter( 'manage_users_columns', 'column_register_wpse_101322' );
455add_filter( 'manage_users_custom_column', 'column_display_wpse_101322', 10, 3 );
456
457function column_register_wpse_101322( $columns )
458{
459 $columns['Aprovação'] = 'Aprovação';
460 return $columns;
461}
462
463function column_display_wpse_101322( $empty, $column_name, $user_id )
464{
465
466 return '<a href="admin.php?action=promoverole&user_id=' . $user_id . '">Aprovar membro</a>';
467}
468
469add_action( 'user_alter_perm', 'promove_user_role_for_adm', 10,0);
470do_action('user_alter_perm');
471function promove_user_role_for_adm(){
472
473 if(isset($_GET['user_id']) && $_GET['action']=='promoverole'){
474 $id = (int)$_GET['user_id'];
475 $user = new WP_User($id);
476 $user->remove_role('lojistaanalise');
477 $user->add_role('subscriber');
478 update_user_meta( $id, '_lojista_status' , 2);
479 /*
480 *$mailer = WC()->mailer();
481
482 $mailer->send( get_option( 'admin_email' ), $subject, $mailer->wrap_message( $title, $message ) );
483 */
484 wp_redirect('/wp-admin/users.php');
485 }
486}
487
488add_action('create_subscriber_user', 'create_subscriber_user_func', 10,0);
489do_action('create_subscriber_user');
490
491function create_subscriber_user_func(){
492 //var_dump($_POST);
493 //exit;
494 if(empty($_POST['register_subscriber'])){
495 return false;
496 }
497
498 if($_POST['username'] !== ""){
499 $username = wp_slash($_POST['username']);
500 }else{
501 echo "O campo nome é obrigatório";
502 exit;
503 }
504
505 if($_POST['pass'] != "" && $_POST['psw-repeat'] != '' && $_POST['psw-repeat'] == $_POST['psw-repeat']){
506 $pass = wp_slash($_POST['pass']);
507 }
508 else{
509 echo "As senhas não conferem.";
510 exit;
511 }
512
513 if($_POST['email'] != ""){
514 $email = wp_slash($_POST['email']);
515 }
516
517 if($_POST['cnpj'] != ""){
518 $cnpj = wp_slash($_POST['cnpj']);
519 }
520
521 if($_POST['telefone'] != ""){
522 $fone = wp_slash($_POST['telefone']);
523 }
524 else{
525 echo "telefone deve ser preenchido";
526 exit;
527 }
528
529 if($_POST['rsocial'] != ""){
530 $rsocial = wp_slash($_POST['rsocial']);
531 }else{
532 echo "campo obrigatório";
533 exit;
534 }
535
536 if($_POST['estado'] != ""){
537 $estado = wp_slash($_POST['estado']);
538 }else{
539 echo "campo obrigatório";
540 exit;
541 }
542
543 if($_POST['instagram'] != ""){
544 $instagram = wp_slash($_POST['instagram']);
545 }else{
546 echo "campo obrigatório";
547 exit;
548 }
549
550 if($_POST['inc_estadual'] != ""){
551 $inc_estadual = wp_slash($_POST['inc_estadual']);
552 }else{
553 echo "campo obrigatório";
554 exit;
555 }
556 // ----------------------------------------------------
557 // This is just a security precaution, to make sure the above "Config Variables"
558 // have been changed from their default values.
559 // Check that user doesn't already exist
560 if( !username_exists($username) && !email_exists($email) ) {
561// if( !email_exists($email) ) {
562 // Create user and set role to administrator
563 $user_id = wp_create_user($username,$pass,$email);
564
565 if (is_int($user_id))
566 {
567 $wp_user_object = new WP_User($user_id);
568 $wp_user_object->set_role('lojistaanalise');
569 update_user_meta( $user_id, "first_name",$username);
570 update_user_meta( $user_id, "user_email",$email);
571 update_user_meta( $user_id, 'billing_cnpj' , $cnpj);
572 update_user_meta( $user_id, 'rsocial' , $rsocial);
573 update_user_meta( $user_id, 'instagram' , $instagram);
574 update_user_meta( $user_id, 'billing_cellphone' , $fone);
575 update_user_meta( $user_id, '_lojista_status' , 1);
576 update_user_meta( $user_id, 'billing_state' , $estado);
577 update_user_meta( $user_id, 'shipping_state' , $estado);
578 update_user_meta( $user_id, 'inc_estadual' , $inc_estadual);
579 //enviando email
580 $to = 'comercial@vasap.com.br';
581 $subject = 'Cadastro de Lojista';
582 $body = '<h2>Dados do Cadastro de Lojista</h2>';
583 $body .= "<b>Nome:</b>: " . $username . " <br>";
584 $body .= "<b>Email:</b> " . $email . " <br>";
585 $body .= "<b>Estado:</b> " . $estado . " <br>";
586 $body .= "<b>Instagram:</b> " . $instagram . " <br>";
587 $body .= "<b>Cnpj: </b>" . $cnpj . " <br>";
588 $body .= "<b>Razão Social:</b> " . $rsocial . " <br>";
589 $body .= "<b>Telefone:</b> " . $fone . " <br>";
590 $body .= "<b>Inscrição Estadual:</b> " . $inc_estadual . " <br>";
591
592 $headers = array('Content-Type: text/html; charset=UTF-8');
593 wp_mail( $to, $subject, $body, $headers );
594
595 wp_redirect("/obrigado-varejista/");
596 exit;
597 /*
598 if(isset($_POST['register_subscriber'])){
599 var_dump($_POST);exit;
600 }
601 */
602 //echo 'Successfully created new admin user. Now delete this file!';
603 }
604 else {
605 echo 'Error with wp_insert_user. No users were created.';
606 }
607 }
608 else {
609 echo 'Email já cadastrado na nossa base de dados.';
610 exit;
611 }
612}
613
614
615add_action('edit_user_profile', 'mysite_show_extra_profile_fields');
616function mysite_show_extra_profile_fields($user) {
617
618 $custom_meta_fields = [];
619 $custom_meta_fields['rsocial'] = 'Razão Social';
620 $custom_meta_fields['inc_estadual'] = 'Inscrição Estadual';
621
622 $meta_number = 0;
623 $custom_meta_fields = $custom_meta_fields;
624
625 print('<h3>Dados customizados do Usuário</h3>');
626 print('<table class="form-table">');
627
628 foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
629 $meta_number++;
630 print('<tr>');
631 print('<th><label for="' . $meta_field_name . '">' . $meta_disp_name . '</label></th>');
632 print('<td>');
633 print('<input type="text" name="' . $meta_field_name . '" id="' . $meta_field_name . '" value="' . esc_attr( get_the_author_meta($meta_field_name, $user->ID ) ) . '" class="regular-text" /><br />');
634 print('<span class="description"></span>');
635 print('</td>');
636 print('</tr>');
637 }
638
639 print('</table>');
640}
641
642/*
643
644add_action('edit_user_profile', 'mysite_show_extra_profile_fields');
645function mysite_show_extra_profile_fields($user) {
646 print('<h3>Extra profile information</h3>');
647 print('<table class="form-table">');
648 $meta_number = 0;
649 $custom_meta_fields = mysite_custom_define();
650 foreach ($custom_meta_fields as $meta_field_name => $meta_disp_name) {
651 $meta_number++;
652 print('<tr>');
653 print('<th><label for="' . $meta_field_name . '">' . $meta_disp_name . '</label></th>');
654 print('<td>');
655 print('<input type="text" name="' . $meta_field_name . '" id="' . $meta_field_name . '" value="' . esc_attr( get_the_author_meta($meta_field_name, $user->ID ) ) . '" class="regular-text" /><br />');
656 print('<span class="description"></span>');
657 print('</td>');
658 print('</tr>');
659 }
660 print('</table>');
661}
662
663function mysite_custom_define() {
664 $custom_meta_fields = array();
665 $custom_meta_fields['rsocial'] = 'rsocial'; //Here, one by one, the custom fields that you have in your Ultimate Member plugin
666 return $custom_meta_fields;
667}*/
668
669/*
670function cwp_cash_delivery_disable_customer( $available_gateways ) {
671 global $woocommerce;
672
673 if ( isset( $available_gateways['cod'] ) && current_user_can('subscriber') ) {
674 unset( $available_gateways['cod'] );
675 }
676
677 if ( isset( $available_gateways['pagseguro'] ) && current_user_can('subscriber') ) {
678 unset( $available_gateways['pagseguro'] );
679 }
680
681 return $available_gateways;
682}
683
684add_filter( 'woocommerce_available_payment_gateways', 'cwp_cash_delivery_disable_customer' );
685*/
686//permite acesso via URL para rest request
687
688
689add_filter( 'woocommerce_rest_check_permissions', 'my_woocommerce_rest_check_permissions', 90, 4 );
690function my_woocommerce_rest_check_permissions( $permission, $context, $object_id, $post_type ){
691 return true;
692}
693
694
695function widget_categories_args_filter($cat_args) {
696 $exclude_arr = array(117,16,168,1,19);
697
698 if( isset( $cat_args['exclude'] ) && !empty( $cat_args['exclude'] ) )
699 $exclude_arr = array_unique( array_merge( explode( ',', $cat_args['exclude'] ), $exclude_arr ) );
700 $cat_args['exclude'] = implode( ',', $exclude_arr );
701 return $cat_args;
702 }
703
704add_filter( 'widget_categories_args', 'widget_categories_args_filter', 10, 1 );
705
706//add_action('init', "updateProducts");
707
708function updateProducts(){
709
710//wp_set_object_terms($productID, array('product_tag1','product_tag2','product_tag3'), 'product_tag');
711 if(isset($_GET['script'])){
712
713 // Get draft products.
714 $args = array(
715 'limit' => 300,
716 'return'=>'ids'
717 );
718
719 $products = wc_get_products($args);
720
721 foreach($products as $pId){
722 wp_set_object_terms($pId, array('lojista'), 'product_tag');
723 }
724
725 $args = array(
726 'tags'=>'lojista',
727 'limit'=>200
728 );
729
730 $products2 = wc_get_products( $args );
731
732 var_dump(count($products2));
733 exit;
734
735 }
736
737}
738
739//add_action( 'save_post', 'add_tag_to_product', 10, 3 );
740function add_tag_to_product( $post_id, $post, $update ) {
741
742 if ($post->post_type != 'product') return; // Only products
743 if (defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
744 return $post_id;
745
746 // Check the user's permissions.
747 if ( ! current_user_can( 'edit_product', $post_id ) )
748 return $post_id;
749
750 $product = wc_get_product( $post_id ); // The WC_Product object
751 wp_set_object_terms($product->get_id(), array('lojista'), 'product_tag');
752 // if product is not on sale
753
754}
755
756/*
757add_filter( 'rest_pre_echo_response', function( $response, $object, $request ) {
758 $product_attribute = array();
759 //$response->data["line_items"] = array("testKey"=>'testValue');
760 for($i=0;$i<count($response['line_items']);$i++){
761 $product[$i] = wc_get_product($response['line_items'][$i]['product_id']);
762 foreach($product[$i]->get_attributes() as $k=>$attribute){
763 if($attribute->get_name() == 'id'){
764 $prod = $attribute;
765 $response['line_items'][$i]['meta_data'] = array("_id_exportacao"=>$prod->get_options()[0]);
766 }
767 }
768
769 }
770 //$response->data['meta_data']['key'] = 'user_rest_request';
771 return $response;
772 }, 10, 3 );
773 */
774
775//add_filter( 'wc_product_has_unique_sku', '__return_false' );
776
777
778//add_action( 'init', 'wpname_unregister_taxonomy' );
779
780function wpname_unregister_taxonomy() {
781 $args = array(
782 'limit' => 200,
783 'return'=>'ids',
784 'tag'=>'instashop'
785 );
786
787 $products = wc_get_products($args);
788 $arraySTR = 'array(';
789 foreach($products as $k=>$prod){
790
791 $arraySTR .= $prod . ',';
792 }
793 $arraySTR .= ');';
794
795 echo($arraySTR);
796 exit;
797}
798
799//add_action('init','updateTaxonomy');
800#10% array(13771,10932,9452);
801#50% (array(13842,13771,11591,11585,11579,11576,11575,11569,11566,10982,10980,10978,10976,10973,10960,10958,10956,10932,9372,9369,9367,9364,9363,9327,9321,9196,9192,9187,9179,8900,8867,8838,8810,8782,8754,5445,4611,4586,4408,4382,3851,3579,3466); )
802#alexhanazaki array(9515,9502,9477);
803#andrelenza array(13842,9196,8900,8867,3364,);
804#bacia array(9292,9282);
805#banquetajardim array(9192,4586,);
806#blackfriday array(16092,16085,13771,13266,12556,12548,12544,12534,11591,11585,11579,11576,11575,11569,11566,10982,10980,10978,10976,10973,10960,10958,10956,10932,9571,9562,9556,9548,9536,9515,9502,9477,9452,9372,9369,9367,9364,9363,9327,9321,9292,9282,9252,9244,9228,9220,9192,9187,9177,9170,9164,9150,9144,9138,9103,9078,9069,9061,9054,9017,8981,8959,8937,8900,8867,8838,8810,8782,8754,7693,6244,6213,5800,5766,5724,5619,5586,5541,5507,5482,5445,5326,4611,4586,4487,4408,4382,4334,4324,4317,4281,4264,4205,4146,4087,3970,3912,3851,3652,3618,3579,3562,3466,3436,3364,3289,3237,3080,2793,);
807#casavasap array(9641,9252,9179,9078,8867,4611,4586);
808#combinadinho array(11591,11585,11579,11576,11575,11569,11566,10982,10980,10978,10976,10973,10960,10958,10956,9372,9369,9367,9364,9363,9327,);
809#composicao array(18126,16937,16238,14145,13358,13270,13235,12633,12404,11229,10343,10172,10137,10135,10064,9712,9464,9323,9322,9320,9307,9305,9303,);
810#cumbuca 194 array(3652,2793,);
811#desc array(15713,13266,12556,12548,12544,12534,9292,9252,9244,9179,9061,6213,5724,5445,5303,4611,4586,4334,4205,4087,3579,3562,3436,);
812#desconto array(13771,10932);
813#descontoabril array(15713,9369,5303,3562,);
814#destaque array(16999,16386,15464,15378,15020,15005,15003,15000,14621,12926,12887,12402,12394,12383,12380,10260,10062,);
815#hanazaki array(9515,9502,9477,);
816#home array(4611,4586);
817#jardineira array(8810,3618,3579,);
818#kony array(9069,3080,);
819#macrame array(9177,7693,);
820#minikit array(19184,16450,15813,15807,15804,15797,15232,15226,15220,15213,15211,15208,15202,14998,);
821#oval array(9515,9502,9477,);
822#prato array(4487,4408,);
823#prisma array(8838,8810,8782,);
824#quadrado 199 array(8867,8838,8782,3364,); (pro)
825#ripado array(8900,8867,3364,);
826#rosenbaum array(3652,3618,3579,2793,);
827#suculentas
828#suporte 186 array(16092,16085,9571,9562,9556,9548,9536,9452,9177,8754,7693,4382,4334,4324,4317,4281,4264,);
829#tripe array(4324,4317,4281,4264,);
830#vaso array(9641,9633,9252,9244,9236,9228,9220,9069,8900,8867,8838,8810,8782,3652,3618,3579,3562,3364,3080,2793,);
831#vasoconeliso array(9103,6244,6213,3912,);
832#vietnamita array(9641,9633,9252,9244,9236,9228,9220,);
833#zanini array(9069,3562,3080);
834#30 array(13266,12556,12548,12544,12534,9641,9633,9571,9562,9292,9282,9252,9244,9236,9220,9177,9170,9164,9157,9150,9144,9138,9103,9078,9061,9054,9017,8981,8959,8937,6244,5800,5766,5724,5619,5586,5541,5507,5482,4205,3912,3289,3237,);
835#40 array(16092,16085,15713,9556,9548,9536,9515,9502,9477,9069,5326,5303,3562,);
836#instashop array(18126,16937,16238,14145,13771,13358,13270,13235,12633,12404,11229,10932,10343,10172,10137,10135,10066,10064,9712,9464,9323,9322,9320,9307,9305,9303,);
837
838function updateTaxonomy(){
839 if(isset($_GET['exportTax'])){
840 $p = array(18126,16937,16238,14145,13771,13358,13270,13235,12633,12404,11229,10932,10343,10172,10137,10135,10066,10064,9712,9464,9323,9322,9320,9307,9305,9303);
841 foreach($p as $prod):
842 wp_set_object_terms($prod,227, 'product_tag', $append=true);
843 endforeach;
844 echo 'sucesso'; exit;
845 }
846
847}
848
849//add_filter('woocommerce_get_price','custom_price_WPA111772', 10, 2);
850//add_filter('woocommerce_get_regular_price','custom_price_WPA111772', 10, 2);
851//add_filter('woocommerce_get_sale_price','custom_price_WPA111772', 10, 2);
852//add_filter( 'woocommerce_product_get_price', 'custom_price_WPA111772', 10, 2 );
853//add_filter( 'woocommerce_product_variation_get_price', 'custom_price_WPA111772', 10, 2);
854//woocommerce_product_variation_get_price (work)
855//woocommerce_variation_prices_regular_price (work)
856
857/**
858 * custom_price_WPA111772
859 *
860 * filter the price based on category and user role
861 * @param $price
862 * @param $product
863 * @return
864 */
865function custom_price_WPA111772($price, $product) {
866 $priceList = [];
867 if (!is_user_logged_in()) return $price;
868 //check if the product is in a category you want, let say shirts
869 //check if the user has a role of dealer using a helper function, see bellow
870 if (has_role_WPA111772('subscriber')){
871 //give user 10% of
872 //print_r($product->get_available_variations());
873 //foreach($product->get_variation_prices()['price'] as $k=>$pricev){
874 // $priceList[] = $pricev;
875 //}
876
877 $price = $price*0.8;
878 var_dump($price);
879
880 }
881
882 //var_dump($priceList);exit;
883
884 return $price;
885}
886
887/**
888* has_role_WPA111772
889*
890* function to check if a user has a specific role
891*
892* @param string $role role to check against
893* @param int $user_id user id
894* @return boolean
895*/
896function has_role_WPA111772($role = '',$user_id = null){
897 if ( is_numeric( $user_id ) )
898 $user = get_user_by( 'id',$user_id );
899 else
900 $user = wp_get_current_user();
901
902 if ( empty( $user ) )
903 return false;
904
905 return in_array( $role, (array) $user->roles );
906}
907
908// Applying conditionally a discount for a specific user role
909//add_action( 'woocommerce_cart_calculate_fees', 'discount_based_on_user_role', 20, 1 );
910function discount_based_on_user_role( $cart ) {
911 if ( is_admin() && ! defined( 'DOING_AJAX' ) )
912 return; // Exit
913
914 // Only for 'company' user role
915 #if ( ! current_user_can('company') )
916 # return; // Exit
917
918 // HERE define the percentage discount
919
920 ##$discount = $cart->get_subtotal() * $percentage / 100; // Calculation
921 ##foreach($cart->cart_contents as $k=>$cart){
922 # $cart['line_subtotal'] = $cart['line_subtotal'] *2;
923 #}
924 if (has_role_WPA111772('subscriber')){
925 //give user 10% of
926 //print_r($product->get_available_variations());
927 //foreach($product->get_variation_prices()['price'] as $k=>$pricev){
928 // $priceList[] = $pricev;
929 //}
930
931 //$price = $price*0.8;
932 //var_dump($price);
933
934 $acrescimo = $cart->get_subtotal() * 0.15;
935 $cart->add_fee("Acréscimo de 15% para Lojista",$acrescimo,false,$taxClass=false);
936
937 }
938
939 // print_r($cart['line_subtotal']);
940 // Applying discount
941
942 return $cart;
943}
944
945
946add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_orderby' );
947
948function woocommerce_shortcode_products_orderby( $args ) {
949 if( is_account_page() && is_user_logged_in() && has_role_WPA111772('subscriber') ){
950 //$standard_array = array('menu_order','title','date','rand','id');
951 //$args['meta_key'] = '_alg_wc_price_by_user_role_sale_price_subscriber';
952 $args['meta_key'] = '_alg_wc_price_by_user_role_per_product_settings_enabled';
953 $args['meta_value'] = "yes";
954 //print_r($args);
955 return $args;
956 }
957}
958
959add_action('pre_user_query', 'change_user_order');
960
961function change_user_order($query) {
962
963 $query->query_orderby = ' ORDER BY ID DESC';
964}
965
966add_action( 'init', 'stop_heartbeat', 1 );
967function stop_heartbeat() {
968 wp_deregister_script('heartbeat');
969}
970
971
972if ( is_admin() ) {
973 add_action( 'admin_menu', 'add_products_menu_entry', 100 );
974}
975
976function add_products_menu_entry() {
977 add_submenu_page(
978 'edit.php?post_type=product',
979 __( 'Lojista' ),
980 __( 'Lojista' ),
981 'manage_woocommerce', // Required user capability
982 'ddg-product',
983 'generate_grab_product_page'
984 );
985}
986
987function generate_grab_product_page() {
988 product_price_filter_box();
989}
990//_alg_wc_price_by_user_role_regular_price_subscriber
991//_alg_wc_price_by_user_role_sale_price_subscriber
992function product_price_filter_box() {
993
994 $query = array(
995 'post_status' => 'publish',
996 'post_type' => 'product',
997 'posts_per_page' => 100,
998 'meta_query' => array(
999 'relation' => 'AND',
1000 array(
1001 'key' => '_alg_wc_price_by_user_role_per_product_settings_enabled',
1002 'value' => 'yes'
1003 ),
1004 ['key'=>'_alg_wc_price_by_user_role_regular_price_subscriber', 'value'=>'10', 'compare'=>'<'],
1005 ['key'=>'_alg_wc_price_by_user_role_sale_price_subscriber', 'value'=>'10', 'compare'=>'<']
1006 )
1007 );
1008
1009 $wpquery = new WP_Query($query);
1010 if($wpquery->have_posts()){
1011
1012 while($wpquery->have_posts()) {
1013 $wpquery->the_post();
1014 echo '<a href="' . 'post.php?post=' . get_the_ID() . '&action=edit' . '">' . get_the_title() . '</a><br>';
1015 }
1016
1017 wp_reset_postdata();
1018 }
1019}
1020
1021
1022add_action( 'woocommerce_check_cart_items', 'spyr_set_min_total' );
1023
1024function spyr_set_min_total() {
1025
1026 if(has_role_WPA111772('subscriber')) {
1027 if(is_cart() || is_checkout()){
1028 global $woocommerce;
1029
1030 $minimum_cart_total = 1000;
1031
1032 $total = WC()->cart->subtotal;
1033
1034 if( $total <= $minimum_cart_total ) {
1035 $saldo = $minimum_cart_total - $total;
1036 $saldo_dec = number_format((float)$saldo, 2, ',', '');
1037 $singular = '<br />Falta <strong>R$ %s</strong> para atingir o valor mínimo.</div>';
1038 $plural = '<br />Faltam <strong>R$ %s</strong> para atingir o valor mínimo.</div>';
1039 if ( $saldo > 1 || $saldo < 1 ) {
1040 $msg = $plural;
1041 } else {
1042 $msg = $singular;
1043 }
1044
1045 if ( $total != 0 ) {
1046 wc_add_notice( sprintf( '<div style="font-size: 15px;"><strong>O Pedido deve ter o valor mínimo de R$ %s.</strong>'
1047 .'<br />O Valor total do seu pedido agora é de <strong>R$ %s</strong>.'
1048 .$msg,
1049 number_format((float)$minimum_cart_total, 2, ',', ''),
1050 number_format((float)$total, 2, ',', ''),
1051 $saldo_dec ),
1052 'error' );
1053 }
1054 }
1055 }
1056 }
1057}
1058
1059
1060
1061 /**
1062 * Remove product data tabs
1063 */
1064add_filter( 'woocommerce_product_tabs', 'woo_remove_product_tabs', 98 );
1065
1066function woo_remove_product_tabs( $tabs ) {
1067
1068 //unset( $tabs['description'] ); // Remove the description tab
1069 unset( $tabs['reviews'] ); // Remove the reviews tab
1070 unset( $tabs['additional_information'] ); // Remove the additional information tab
1071
1072 return $tabs;
1073}
1074
1075
1076
1077// jQuery - Ajax script
1078add_action( 'wp_footer', 'checkout_shipping_packing_script' );
1079function checkout_shipping_packing_script() {
1080 // Only checkout page
1081 if(!has_role_WPA111772('subscriber')){
1082 return ;
1083 }
1084
1085 if ( is_checkout() && ! is_wc_endpoint_url() ) :
1086
1087 WC()->session->__unset('billing_state');
1088 ?>
1089 <script type="text/javascript">
1090 jQuery( function($){
1091 jQuery('form.checkout').on('blur', '#billing_postcode', function(e){
1092 e.preventDefault();
1093 var p = jQuery("#billing_postcode").val();
1094
1095 console.log(p);
1096 //alert(p);
1097 jQuery.ajax({
1098 type: 'POST',
1099 url: wc_checkout_params.ajax_url,
1100 data: {
1101 'action': 'woo_get_ajax_data',
1102 'billing_state': p,
1103 },
1104 success: function (result) {
1105 $('body').trigger('update_checkout');
1106 //var htmlString = $(".packing-select").html();
1107 //$(".packing-select").text(result );
1108 //alert(result);
1109 //console.log('response: '+result); // just for testing | TO BE REMOVED
1110 $("#billing_postcode").attr('readonly','readonly');
1111 //$("#billing_state").attr('disabled','disabled');
1112 /*$('form#id').submit(function(){
1113 $(this).find('#billing_state').prop('disabled', true);
1114 });*/
1115 },
1116 error: function(error){
1117 //console.log(error); // just for testing | TO BE REMOVED
1118 }
1119 });
1120 });
1121 });
1122 </script>
1123 <?php
1124 endif;
1125}
1126
1127add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
1128
1129function custom_override_default_address_fields( $address_fields ) {
1130
1131 // we are changing here billing_state field to required
1132 $address_fields['billing']['billing_state']['required'] = true;
1133
1134 return $address_fields;
1135}
1136
1137// Php Ajax (Receiving request and saving to WC session)
1138add_action( 'wp_ajax_woo_get_ajax_data', 'woo_get_ajax_data' );
1139add_action( 'wp_ajax_nopriv_woo_get_ajax_data', 'woo_get_ajax_data' );
1140function woo_get_ajax_data() {
1141 if(!has_role_WPA111772('subscriber')){
1142 return;
1143 }
1144 if ( isset($_POST['billing_state']) ){
1145 $packing = sanitize_key( $_POST['billing_state'] );
1146 WC()->session->set('billing_state', $packing );
1147 echo json_encode( $packing );
1148 }
1149 die(); // Alway at the end (to avoid server error 500)
1150}
1151
1152// Add a custom dynamic packaging fee
1153add_action( 'woocommerce_cart_calculate_fees', 'add_packaging_fee', 10, 1 );
1154function add_packaging_fee( $cart ) {
1155 if ( is_admin() && ! defined( 'DOING_AJAX' ) )
1156 return;
1157
1158 $user = wp_get_current_user();
1159 $current_user_uf = $user->billing_state;
1160
1161 $domain = "woocommerce";
1162 //$packing_fee = WC()->session->get( 'billing_state' ); // Dynamic packing fee
1163 $cep_digitado_textField = WC()->session->get('billing_state');
1164 $xml = get_endereco($cep_digitado_textField);
1165 $json_string = json_encode($xml);
1166 $result_array = json_decode($json_string, TRUE);
1167 //estado correspondente ao webservice/consulta cep
1168 $state_current_checkout = $result_array['uf'];
1169
1170 //$label = __("ajax_session_uf:{$cep_digitado_textField} current_user_uf:{$current_user_uf}|", $domain);
1171 //$cost = 3.00;
1172 $statesListRestrictions = ['PI', 'BA','PE', 'MA','AL','CE','PB','RN','SE','AC','AP','AM','PA','RO','RR','TO'];
1173
1174 $percent = 10;
1175 $percentNorte = 15;
1176
1177 $isError = false;
1178 if(has_role_WPA111772('subscriber')){
1179 foreach($statesListRestrictions as $list){
1180 if(isset($state_current_checkout)){
1181 if(isset($current_user_uf) && $current_user_uf == $list && $state_current_checkout == $current_user_uf){
1182 // Calculation
1183 if($current_user_uf == "PA" || $current_user_uf == "TO" || $current_user_uf == "RO" || $current_user_uf == "AC" || $current_user_uf == "AP" || $current_user_uf == "AM" || $current_user_uf == "RR"){
1184 $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percentNorte / 100;
1185 $cart->add_fee( __( ' ' . " TAXA de {$percentNorte}% para Entregas no Estado:{$current_user_uf}")." ($percentNorte%)", $surcharge, false );
1186 // $wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1187 return $surcharge;
1188 }
1189
1190 $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percent / 100;
1191 $cart->add_fee( __( ' ' . " TAXA de {$percent}% para Entregas no Estado:{$current_user_uf}")." ($percent%)", $surcharge, false );
1192 //$wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1193 return $surcharge;
1194
1195
1196 // Add the fee (tax third argument disabled: false)
1197 // Add the fee (tax third argument disabled: false)
1198
1199 }else{
1200 //print_r( " 1(false)TAXA de {$percent}% para Entregas no Estado:{$current_user_uf}|estadoCorrente:{$state_current_checkout} no cep: {$cep_digitado_textField}");
1201 //WC()->session->__unset('billing_state');
1202 //wc_add_notice( __( 'Sua Cidade de Cadastro Diverge da que foi colocada neste formulário' ), 'error' );
1203 // We are trying to redirect to another site, using a hard-coded URL.
1204 //wp_redirect( 'https://labs.vasap.com.br/carrinho' );
1205 $isError = true;
1206 }
1207
1208 if($state_current_checkout == $current_user_uf && $current_user_uf == $list && is_checkout()){
1209 if($current_user_uf == "PA" || $current_user_uf == "TO" || $current_user_uf == "RO" || $current_user_uf == "AC" || $current_user_uf == "AP" || $current_user_uf == "AM" || $current_user_uf == "RR"){
1210 $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percentNorte / 100;
1211 $cart->add_fee( __( ' ' . " TAXA de {$percentNorte}% para Entregas no Estado:{$current_user_uf}")." ($percentNorte%)", $surcharge, false );
1212 // $wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1213 return $surcharge;
1214 }
1215
1216 $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percent / 100;
1217 $cart->add_fee( __( ' ' . "& TAXA de {$percent}% para Entregas no Estado:{$current_user_uf} | {$state_current_checkout}")." ($percent%)", $surcharge, false );
1218 //$wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1219 return $surcharge;
1220
1221 }else{
1222 //print_r( " 2(false) TAXA de {$percent}% para Entregas no Estado:{$current_user_uf}|estadoCorrente:{$state_current_checkout} no cep: {$cep_digitado_textField}");
1223 //WC()->session->__unset('billing_state');
1224 //wc_add_notice( __( 'Sua Cidade de Cadastro Diverge da que foi colocada neste formulário' ), 'error' );
1225
1226 // We are trying to redirect to another site, using a hard-coded URL.
1227 //wp_redirect( 'https://labs.vasap.com.br/carrinho' );
1228 $isError = true;
1229 }
1230 }
1231
1232
1233 if(isset($current_user_uf) && $current_user_uf == $list && empty($state_current_checkout)){
1234 if($current_user_uf == "PA" || $current_user_uf == "TO" || $current_user_uf == "RO" || $current_user_uf == "AC" || $current_user_uf == "AP" || $current_user_uf == "AM" || $current_user_uf == "RR"){
1235 $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percentNorte / 100;
1236 $cart->add_fee( __( ' ' . " TAXA de {$percentNorte}% para Entregas no Estado:{$current_user_uf}")." ($percentNorte%)", $surcharge, false );
1237 // $wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1238 return $surcharge;
1239 }
1240 $surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percent / 100;
1241 $cart->add_fee( __( ' ' . "TAXA de {$percent}% para Entregas no Estado:{$current_user_uf}")." ($percent%)", $surcharge, false );
1242 //$wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1243 return $surcharge;
1244
1245 }else{
1246 // print_r( " 3(false)TAXA de {$percent}% para Entregas no Estado:{$current_user_uf}|estadoCorrente:{$state_current_checkout} no cep: {$cep_digitado_textField}");
1247 //WC()->session->__unset('billing_state');
1248 //wc_add_notice( __( 'Sua Cidade de Cadastro Diverge da que foi colocada neste formulário' ), 'error' );
1249 // We are trying to redirect to another site, using a hard-coded URL.
1250 //wp_redirect( 'https://labs.vasap.com.br/carrinho' );
1251 $isError = false;
1252 }
1253
1254 }
1255
1256 if($isError){
1257 wc_add_notice( __( 'Seu Estado de Cadastro Diverge da que foi colocada neste formulário' ), 'error' );
1258 //header( "refresh:1;url=https://labs.vasap.com.br/finalizar-compra/" );
1259 //wp_redirect( "https://labs.vasap.com.br/finalizar-compra/" ); exit;
1260 // wp_safe_redirect( wc_get_page_permalink( 'checkout' ) );exit;
1261
1262 }
1263
1264 return false;
1265 /*
1266 if(isset($state_current_checkout) && is_checkout()){
1267 if($state_current_checkout != $current_user_uf){
1268 //$surcharge = ( $cart->cart_contents_total + $cart->shipping_total ) * $percent / 100;
1269 // Add the fee (tax third argument disabled: false)
1270 // Add the fee (tax third argument disabled: false)
1271 //$cart->add_fee( __( ' ' . " (Problema no Estado)TAXA de {$percent}% para Entregas no Estado:{$current_user_uf}|estadoCorrente:{$state_current_checkout} no cep: {$cep_digitado_textField}")." ($percent%)", $surcharge, false );
1272 // $wc->cart->add_fee( __("TAXA de {$percent}% para Entregas no Estado:{$state} | {$customer_state} | {$customer_postcode}", 'woocommerce')." ($percent%)", $surcharge, false );
1273 //wc_add_notice( __( 'Sua Cidade de Cadastro Diverge da que foi colocada neste formulário' ), 'error' );
1274 // We are trying to redirect to another site, using a hard-coded URL.
1275 wp_redirect( 'https:/labs.vasap.com.br/carrinho' );
1276 //return $surcharge;
1277 }
1278
1279 }*/
1280 }
1281
1282}
1283
1284
1285// Field validation, as this packing field is required
1286add_action('woocommerce_checkout_process', 'packing_field_checkout_process');
1287function packing_field_checkout_process() {
1288 if(!has_role_WPA111772('subscriber')){
1289 return ;
1290 }
1291 // Check if set, if its not set add an error.
1292 if ( isset($_POST['billing_state']) && empty($_POST['billing_state']) )
1293 wc_add_notice( __( "Please choose a packing option...", "woocommerce" ), 'error' );
1294}
1295
1296
1297function get_endereco($cep){
1298
1299
1300 // formatar o cep removendo caracteres nao numericos
1301 $cep = preg_replace("/[^0-9]/", "", $cep);
1302 $url = "http://viacep.com.br/ws/$cep/xml/";
1303
1304 $xml = simplexml_load_file($url);
1305 if(empty($xml)){
1306 return null;
1307 }else{
1308 return $xml;
1309 }
1310
1311
1312}
1313add_action( 'woocommerce_checkout_create_order', 'action_woocommerce_review_order_before_submit', 10, 2 );
1314// define the woocommerce_review_order_before_submit callback
1315function action_woocommerce_review_order_before_submit($order,$data){
1316 // make action magic happen here...
1317 //var_dump($order);
1318 if(!has_role_WPA111772('subscriber')){
1319 return ;
1320 }
1321 $user = wp_get_current_user();
1322 $current_user_uf = $user->billing_state;
1323 $state = $order->get_billing_state();
1324 //echo "<script>alert('{$current_user_uf}');</script>";
1325 if($state == $current_user_uf){
1326 return true;
1327 }else{
1328 wc_add_notice( __( "* Sua Cidade de Cadastro Diverge da que foi colocada neste formulário" ), 'error' );
1329 exit;
1330 }
1331}
1332
1333// add the action
1334//add_action( 'woocommerce_after_checkout_form', 'action_woocommerce_review_order_before_submit', 10, 0 );
1335
1336
1337❮
1338❯
1339