Changeset 3320210
- Timestamp:
- 06/30/2025 06:51:59 PM (9 months ago)
- Location:
- ceretax
- Files:
-
- 25 added
- 6 edited
-
tags/1.4.3 (added)
-
tags/1.4.3/assets (added)
-
tags/1.4.3/assets/css (added)
-
tags/1.4.3/assets/css/admin.css (added)
-
tags/1.4.3/assets/js (added)
-
tags/1.4.3/assets/js/admin.js (added)
-
tags/1.4.3/assets/js/front.js (added)
-
tags/1.4.3/ceretax.php (added)
-
tags/1.4.3/changelog.txt (added)
-
tags/1.4.3/inc (added)
-
tags/1.4.3/inc/admin (added)
-
tags/1.4.3/inc/admin/class-cwafc-admin-action.php (added)
-
tags/1.4.3/inc/admin/class-cwafc-admin-filter.php (added)
-
tags/1.4.3/inc/admin/class-cwafc-admin.php (added)
-
tags/1.4.3/inc/class-cwafc.php (added)
-
tags/1.4.3/inc/front (added)
-
tags/1.4.3/inc/front/class-cwafc-front-action.php (added)
-
tags/1.4.3/inc/front/class-cwafc-front-filter.php (added)
-
tags/1.4.3/inc/front/class-cwafc-front.php (added)
-
tags/1.4.3/languages (added)
-
tags/1.4.3/languages/ceretax.pot (added)
-
tags/1.4.3/readme.txt (added)
-
tags/1.4.3/woocommerce (added)
-
tags/1.4.3/woocommerce/cart (added)
-
tags/1.4.3/woocommerce/cart/shipping-calculator.php (added)
-
trunk/ceretax.php (modified) (2 diffs)
-
trunk/changelog.txt (modified) (1 diff)
-
trunk/inc/admin/class-cwafc-admin-action.php (modified) (15 diffs)
-
trunk/inc/class-cwafc.php (modified) (65 diffs)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/woocommerce/cart/shipping-calculator.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ceretax/trunk/ceretax.php
r3285848 r3320210 4 4 * Plugin URI: https://wordpress.org/plugins/ceretax/ 5 5 * Description: Simplify sales tax complexity with CereTax for WooCommerce. 6 * Version: 1.4. 26 * Version: 1.4.3 7 7 * Author: CereTax, Inc. 8 8 * Author URI: https://www.ceretax.com/ … … 14 14 * 15 15 * Woo: 12345:342928dfsfhsf8429842374wdf4234sfd 16 * WC requires at least: 6.017 * WC tested up to: 8.016 * WC requires at least: 7.0.0 17 * WC tested up to: 9.9.5 18 18 * 19 19 * License: GNU General Public License v3.0 -
ceretax/trunk/changelog.txt
r3285848 r3320210 52 52 * fix - System now supports multiple partial refunds on a single order, providing greater flexibility in transaction management 53 53 * fix - Corrected recurring subscription product tax display issue on the checkout page to show accurate tax amounts 54 55 2025-05-28 - version 1.4.3 56 * fix - Resolved PHP warning errors 57 * add - Included 'shipFromAddress' parameter in the ceretax API request -
ceretax/trunk/inc/admin/class-cwafc-admin-action.php
r3285848 r3320210 48 48 // Add admin order style and script. 49 49 add_action( 'admin_footer', array( $this, 'action__cwafc_admin_footer_function' ), 20 ); 50 // Add add store address validate button WC general setting tab. 51 add_filter( 'woocommerce_general_settings', array( $this, 'filter__cwafc_add_store_address_validate_button' ) ); 52 // Add render store address validate button. 53 add_action( 'woocommerce_admin_field_validate_store_address_button', array( $this, 'action__cwafc_render_store_address_validate_button' ) ); 54 // Validate_store_address. 55 add_action( 'woocommerce_update_options_general', array( $this, 'action__cwafc_validate_store_address' ) ); 56 // Add custom style after total. 57 add_action( 'woocommerce_admin_order_totals_after_total', array( $this, 'action__cwafc_add_after_total_style' ) ); 50 58 } 51 59 … … 413 421 public function action__cwafc_admin_footer_function() { 414 422 $order_id = null; 423 // phpcs:disable WordPress.Security.NonceVerification.Recommended 415 424 if ( ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) || ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) ) { 416 425 if ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) { 417 $order_id = $_GET['post'];418 } else if ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) {419 $order_id = $_GET['id'];426 $order_id = sanitize_text_field( wp_unslash( $_GET['post'] ) ); 427 } elseif ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) { 428 $order_id = sanitize_text_field( wp_unslash( $_GET['id'] ) ); 420 429 } else { 421 430 $order_id = ''; 422 431 } 423 432 } 433 // phpcs:enable WordPress.Security.NonceVerification.Recommended 424 434 425 435 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); … … 434 444 } 435 445 } 436 if ( ( ! empty( $order_id ) && ! empty( $ceretax_data ) && $fee_amount > 0 ) || ( 'shop_order' === get_post_type( $order_id ) && empty( $ceretax_data ) ) ) { ?> 437 <style> 438 /* Hide the 3rd tr of .wc-order-totals if .wc-used-coupons is found */ 439 .wc-order-data-row:has(.wc-used-coupons) .wc-order-totals:first-of-type tr:nth-of-type(3) { 440 display: none !important; 441 } 442 443 /* Hide the 2nd tr of .wc-order-totals if .wc-used-coupons is not found */ 444 .wc-order-data-row:not(:has(.wc-used-coupons)) .wc-order-totals:first-of-type tr:nth-of-type(2) { 445 display: none !important; 446 } 447 448 </style> 449 <?php } if ( ! empty( $order_id ) && ! empty( $ceretax_data ) ) { ?> 446 if ( ! empty( $order_id ) && ! empty( $ceretax_data ) ) { ?> 450 447 <style> 451 448 /* Hide Tax column for ceretax order item list */ … … 456 453 457 454 </style> 458 <?php 459 } 460 ?> 455 <?php } ?> 461 456 <style> 462 457 /* Ceretax table stysle */ … … 481 476 } 482 477 </style> 483 <?php 484 // Refund order script. 485 if ( ! empty( $order_id ) && ! empty( $ceretax_data ) ) { ?> 478 <?php if ( ! empty( $order_id ) && ! empty( $ceretax_data ) ) { // Refund order script. ?> 486 479 <script> 487 480 jQuery(function($) { … … 565 558 jQuery( '.woocommerce_order_items #order_fee_line_items tr' ).each( function() { 566 559 var feeName = jQuery( this ).find('.name .view').text().trim(); 567 var taxName = '<?php echo get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax'); ?>';560 var taxName = '<?php echo esc_js( get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ) ); ?>'; 568 561 if ( feeName === taxName ) { 569 562 jQuery( this ).find( '.refund input' ).hide(); … … 584 577 $ceretax_data_lineitem = get_post_meta( $order->get_id(), 'ceretax_data_lineitem', true ); 585 578 $ceretax_data = get_post_meta( $order->get_id(), 'ceretax_data', true ); 586 // if ( ! empty( $ceretax_data_lineitem ) ) {587 579 if ( ! empty( $ceretax_data_lineitem ) && ! empty( $ceretax_data ) && ! empty( $order ) ) { 588 580 $cere_tax_line_item_column_name = get_option( CWAFC_PREFIX . '_cere_tax_line_item_column_name', 'Tax Total' ); … … 601 593 public function action__cwafc_woocommerce_admin_order_item_values( $product, $item, $item_id ) { 602 594 603 // phpcs:disable WordPress.Security.NonceVerification .Missing595 // phpcs:disable WordPress.Security.NonceVerification 604 596 $order_id = null; 605 597 if ( isset( $_GET['post'] ) && ! empty( $_GET['post'] ) ) { 606 598 $order_id = sanitize_text_field( wp_unslash( $_GET['post'] ) ); 607 } else if ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) {599 } elseif ( isset( $_GET['id'] ) && ! empty( $_GET['id'] ) ) { 608 600 $order_id = sanitize_text_field( wp_unslash( $_GET['id'] ) ); 609 601 } else { … … 613 605 $order_id = sanitize_text_field( wp_unslash( $_POST['order_id'] ) ); 614 606 } 615 // phpcs:enable WordPress.Security.NonceVerification .Missing607 // phpcs:enable WordPress.Security.NonceVerification 616 608 617 609 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); … … 623 615 624 616 if ( ! empty( $product ) ) { 625 626 // $refunded_qty = -1 * $order->get_total_refunded_for_item( $item_id );627 628 617 echo '<td class="ceretax_line_value" width="7%">'; 629 618 if ( is_object( $ceretax_data_lineitem ) && is_object( $ceretax_data ) ) { … … 643 632 $line_item_total_tax = 0; 644 633 645 $filtered = array_filter( $ceretax_items_data, function ( $filtered_item ) use ( $product_id ) { 646 return isset( $filtered_item->itemNumber ) && $filtered_item->itemNumber == $product_id; 647 }); 648 649 $refunded_filtered = array_filter( $ceretax_data, function ( $refunded_item ) use ( $product_id ) { 650 return isset( $refunded_item->itemNumber ) && $refunded_item->itemNumber == $product_id; 651 }); 652 653 $line_item_revenue_amount = ! empty( $filtered ) ? reset( $filtered )->revenue : 0; 634 $filtered = array_filter( 635 $ceretax_items_data, 636 function ( $filtered_item ) use ( $product_id ) { 637 return isset( $filtered_item->itemNumber ) && $filtered_item->itemNumber == $product_id; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 638 } 639 ); 640 641 $refunded_filtered = array_filter( 642 $ceretax_data, 643 function ( $refunded_item ) use ( $product_id ) { 644 return isset( $refunded_item->itemNumber ) && $refunded_item->itemNumber == $product_id; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 645 } 646 ); 647 648 $line_item_revenue_amount = ! empty( $filtered ) ? round( reset( $filtered )->revenue, 2 ) : 0; 654 649 $line_item_taxe_breaks = ! empty( $filtered ) ? reset( $filtered )->taxes : array(); 655 650 656 651 if ( ! empty( $line_item_taxe_breaks ) && is_array( $line_item_taxe_breaks ) ) { 657 652 foreach ( $line_item_taxe_breaks as $key => $val ) { 658 if ( ! empty( $val->calculationBaseAmt ) && ( $val->calculationBaseAmt >= $line_item_revenue_amount ) ) { 659 $line_item_calc_base_amount = $val->calculationBaseAmt; 660 $line_item_total_tax_amount += $val->totalTax; 653 if ( ! empty( $val->calculationBaseAmt ) && ( $val->calculationBaseAmt >= $line_item_revenue_amount ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName 654 $line_item_calc_base_amount = $val->calculationBaseAmt; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 655 $line_item_total_tax_amount += $val->totalTax; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 661 656 } 662 657 } … … 666 661 } 667 662 668 $total_line_tax = ! empty( $filtered ) ? reset( $filtered )->totalTaxLine : null;669 $total_line_refunded_tax = ! empty( $refunded_filtered ) ? reset( $refunded_filtered )->totalTaxLine : null;663 $total_line_tax = ! empty( $filtered ) ? reset( $filtered )->totalTaxLine : null; 664 $total_line_refunded_tax = ! empty( $refunded_filtered ) ? reset( $refunded_filtered )->totalTaxLine : null; 670 665 $ceretax_refunded_line_item_tax = $item->get_meta( '_ceretax_refunded_line_item_tax' ); 671 666 echo '<div class="view">'; 672 echo wc_price( $line_item_total_tax, array( 'currency' => $order->get_currency() ) );673 if ( is_array( $order->get_refunds() ) && count( $order->get_refunds() ) > 0 && ! empty( $ceretax_refunded_line_item_tax ) ) {674 echo '<small class="refunded">' . wc_price( -1 * $ceretax_refunded_line_item_tax, array( 'currency' => $order->get_currency() ) ) . '</small>';675 }667 echo wp_kses_post( wc_price( $line_item_total_tax, array( 'currency' => $order->get_currency() ) ) ); 668 if ( is_array( $order->get_refunds() ) && count( $order->get_refunds() ) > 0 && ! empty( $ceretax_refunded_line_item_tax ) ) { 669 echo '<small class="refunded">' . wp_kses_post( wc_price( -1 * $ceretax_refunded_line_item_tax, array( 'currency' => $order->get_currency() ) ) ) . '</small>'; 670 } 676 671 echo '</div>'; 677 672 … … 688 683 echo '<td class="ceretax_line_value" width="7%">'; 689 684 690 $shipping_tax_amount = 0;691 $shipping_line_total = $item['total'];685 $shipping_tax_amount = 0; 686 $shipping_line_total = $item['total']; 692 687 $ceretax_refunded_line_item_tax = $item->get_meta( '_ceretax_refunded_line_item_tax' ); 693 688 if ( ! empty( $item['total'] ) && is_object( $ceretax_data_lineitem ) ) { 694 689 $ceretax_items_data = $ceretax_data_lineitem->invoice->lineItems; 695 690 if ( ! empty( $ceretax_items_data ) ) { 696 $tt = 0;697 691 $ceretax_items_count = 0; 698 692 foreach ( $ceretax_items_data as $item_data ) { 699 $line_item_tax_breaks = $item_data->taxes;693 $line_item_tax_breaks = $item_data->taxes; 700 694 $transaction_charges_tax = 0; 701 695 $tras_charge_calc_base_amount = 0; 702 696 if ( ! empty( $line_item_tax_breaks ) ) { 703 697 foreach ( $line_item_tax_breaks as $key => $val ) { 704 if ( ! empty( $val->transactionChargesCalculationBaseAmt ) ) { 705 $tras_charge_calc_base_amount = $val->transactionChargesCalculationBaseAmt; 706 $transaction_charges_tax = $transaction_charges_tax + $val->transactionChargesTax; 698 if ( ! empty( $val->transactionChargesCalculationBaseAmt ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName 699 $tras_charge_calc_base_amount = $val->transactionChargesCalculationBaseAmt; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 700 $transaction_charges_tax = $transaction_charges_tax + $val->transactionChargesTax; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 707 701 } 708 702 } 709 703 } 710 704 if ( ! empty( $tras_charge_calc_base_amount ) ) { 711 $ceretax_items_count++; 705 $ceretax_items_count++; // phpcs:ignore WordPress.PHP.PreIncrement.PreIncrement 712 706 $shipping_tax_amount = $shipping_tax_amount + ( $transaction_charges_tax ) * ( $shipping_line_total / $tras_charge_calc_base_amount ); 713 707 } … … 719 713 } 720 714 echo '<div class="view">'; 721 echo wc_price( $shipping_tax_amount, array( 'currency' => $order->get_currency() ) );722 if ( is_array( $order->get_refunds() ) && count( $order->get_refunds() ) > 0 && ! empty( $ceretax_refunded_line_item_tax ) ) {723 echo '<small class="refunded">' . wc_price( -1 * $ceretax_refunded_line_item_tax, array( 'currency' => $order->get_currency() ) ) . '</small>';724 }715 echo wp_kses_post( wc_price( $shipping_tax_amount, array( 'currency' => $order->get_currency() ) ) ); 716 if ( is_array( $order->get_refunds() ) && count( $order->get_refunds() ) > 0 && ! empty( $ceretax_refunded_line_item_tax ) ) { 717 echo '<small class="refunded">' . wp_kses_post( wc_price( -1 * $ceretax_refunded_line_item_tax, array( 'currency' => $order->get_currency() ) ) ) . '</small>'; 718 } 725 719 echo '</div>'; 726 720 … … 735 729 } 736 730 } 731 732 /** 733 * Add store address validate button. 734 * 735 * @param array $settings Setting fields. 736 * @return $settings 737 */ 738 public function filter__cwafc_add_store_address_validate_button( $settings ) { 739 $new_settings = array(); 740 foreach ( $settings as $setting ) { 741 $new_settings[] = $setting; 742 // Insert custom button after the postcode field. 743 if ( isset( $setting['id'] ) && 'store_address' === $setting['id'] && 'sectionend' === $setting['type'] ) { 744 $new_settings[] = array( 745 'type' => 'validate_store_address_button', // Custom type, we'll render it below. 746 'id' => 'validate_store_address', 747 'title' => '', // No label. 748 ); 749 } 750 } 751 return $new_settings; 752 } 753 754 /** 755 * Render store address validate button. 756 * 757 * @return void 758 */ 759 public function action__cwafc_render_store_address_validate_button() { 760 ?> 761 <p class="submit"> 762 <button name="save" class="button-primary woocommerce-save-button" type="submit" value="Validate Address"><?php esc_html_e( 'Validate Address', 'woocommerce' ); ?></button> 763 </p> 764 <?php 765 } 766 767 /** 768 * Validate store address. 769 * 770 * @return mix 771 */ 772 public function action__cwafc_validate_store_address() { 773 774 // phpcs:disable WordPress.Security.NonceVerification 775 $address_1 = isset( $_POST['woocommerce_store_address'] ) ? sanitize_text_field( wp_unslash( $_POST['woocommerce_store_address'] ) ) : ''; 776 $address_2 = isset( $_POST['woocommerce_store_address_2'] ) ? sanitize_text_field( wp_unslash( $_POST['woocommerce_store_address_2'] ) ) : ''; 777 $city = isset( $_POST['woocommerce_store_city'] ) ? sanitize_text_field( wp_unslash( $_POST['woocommerce_store_city'] ) ) : ''; 778 $postcode = isset( $_POST['woocommerce_store_postcode'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['woocommerce_store_postcode'] ) ) ) : ''; 779 $default_country = isset( $_POST['woocommerce_default_country'] ) ? strtoupper( sanitize_text_field( wp_unslash( $_POST['woocommerce_default_country'] ) ) ) : ''; 780 // phpcs:enable WordPress.Security.NonceVerification 781 782 // Get country and state separately. 783 list( $country, $state ) = array_pad( explode( ':', $default_country ), 2, '' ); 784 785 // Get ceretax env and api key. 786 $cere_tax_tax_env = get_option( CWAFC_PREFIX . '_cere_tax_environment' ); 787 $cere_tax_api_key = get_option( CWAFC_PREFIX . '_cere_tax_api_key' ); 788 789 if ( 'production' === $cere_tax_tax_env ) { 790 $api_url = 'https://av.prod.ceretax.net/validate'; 791 } else { 792 $api_url = 'https://av.cert.ceretax.net/validate'; 793 } 794 795 $request_body = array( 796 array( 797 'addressLine1' => $address_1, 798 'city' => $city, 799 'state' => $state, 800 'postalCode' => $postcode, 801 'country' => $country, 802 ), 803 ); 804 805 $body = wp_json_encode( $request_body ); 806 807 // add api request data in wc logs if log option enabled. 808 $this->cwafc_wc_add_custom_logs( $request_body, 'ceretax-store-address-validation-request' ); 809 810 $response = wp_remote_post( 811 $api_url, 812 array( 813 'method' => 'POST', 814 'data_format' => 'body', 815 'body' => $body, 816 'headers' => array( 817 'Accept' => 'application/json', 818 'x-api-key' => $cere_tax_api_key, 819 'Content-Type' => 'application/json', 820 ), 821 'timeout' => 60, 822 ) 823 ); 824 825 // add api response data in wc logs if log option enabled. 826 $this->cwafc_wc_add_custom_logs( $response, 'ceretax-store-address-validation-response' ); 827 828 if ( is_wp_error( $response ) ) { 829 $notice_msg = __( 'Request failed: ', 'ceretax' ); 830 $notice_msg .= $response->get_error_message(); 831 WC_Admin_Settings::add_error( $notice_msg ); 832 return false; 833 } else { 834 $data = wp_remote_retrieve_body( $response ); 835 $data = json_decode( $data, true ); 836 } 837 838 if ( isset( $data['results'][0]['errorMessages'] ) ) { 839 $notice_msg = __( 'Address not validate: ', 'ceretax' ); 840 $notice_msg .= $data['results'][0]['errorMessages'][0]['message']; 841 WC_Admin_Settings::add_error( $notice_msg ); 842 return false; 843 } else { 844 $validated_address_details = $data['results'][0]['validatedAddressDetails']; 845 if ( ! empty( $validated_address_details ) ) { 846 847 // Get validated address. 848 $validated_address_line_1 = sanitize_text_field( wp_unslash( $data['results'][0]['validatedAddressDetails']['addressLine1'] ) ); 849 $validated_address_line_2 = sanitize_text_field( wp_unslash( $data['results'][0]['validatedAddressDetails']['addressLine2'] ) ); 850 $validated_city = sanitize_text_field( wp_unslash( $data['results'][0]['validatedAddressDetails']['city'] ) ); 851 $validated_postal_code = sanitize_text_field( wp_unslash( strtoupper( $data['results'][0]['submittedAddressDetails']['postalCode'] ) ) ); 852 853 // Update validated address. 854 update_option( 'woocommerce_store_address', $validated_address_line_1 ); 855 update_option( 'woocommerce_store_address_2', $validated_address_line_2 ); 856 update_option( 'woocommerce_store_city', $validated_city ); 857 update_option( 'woocommerce_store_postcode', $validated_postal_code ); 858 859 $notice_msg = __( 'Address validate successfully !', 'ceretax' ); 860 WC_Admin_Settings::add_message( $notice_msg ); 861 862 } else { 863 $notice_msg = $data['results'][0]['errorMessages'][0]['message']; 864 WC_Admin_Settings::add_error( $notice_msg ); 865 return false; 866 } 867 } 868 } 869 870 /** 871 * Add WooCommerce logs for custom API call. 872 * 873 * @param object $log_data pass the log data. 874 * @param string $log_source pass the source of the log. 875 * @return void 876 */ 877 public function cwafc_wc_add_custom_logs( $log_data, $log_source ) { 878 $enable_logging = get_option( CWAFC_PREFIX . '_cere_tax_enable_logging' ); 879 if ( 'yes' === $enable_logging ) { 880 $logger = wc_get_logger(); 881 $logger->info( wp_json_encode( $log_data, JSON_PRETTY_PRINT ), array( 'source' => $log_source ) ); 882 } 883 } 884 885 /** 886 * Add custom style after total. 887 * 888 * @param int $order_id Order id. 889 * @return void 890 */ 891 public function action__cwafc_add_after_total_style( $order_id ) { 892 $order = is_a( $order_id, 'WC_Order' ) ? $order_id : wc_get_order( $order_id ); 893 894 if ( ! $order instanceof WC_Order ) { 895 return; 896 } 897 898 $ceretax_data_raw = get_post_meta( $order->get_id(), 'ceretax_data', true ); 899 if ( empty( $ceretax_data_raw ) ) { 900 return; 901 } 902 903 $ceretax_data = json_decode( $ceretax_data_raw ); 904 if ( isset( $ceretax_data->invoice->totalTaxInvoice ) && empty( $ceretax_data->invoice->totalTaxInvoice ) ) { 905 return; 906 } 907 908 $order_total_fees = $order->get_total_fees(); 909 if ( $order_total_fees < 0 ) { 910 return; 911 } 912 913 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); 914 $cere_tax_fee_exist = false; 915 foreach ( $order->get_fees() as $fee_id => $fee ) { 916 if ( $fee->get_name() === $cere_tax_name ) { 917 $cere_tax_fee_exist = true; 918 break; 919 } 920 } 921 922 if ( ! $cere_tax_fee_exist ) { 923 return; 924 } 925 926 if ( 0 < count( $order->get_coupon_codes() ) && 0 < $order->get_total_discount() ) { 927 echo '<style> 928 .wc-order-data-row .wc-order-totals:first-of-type tr:nth-of-type(3) { 929 display: none !important; 930 } 931 </style>'; 932 } else { 933 echo '<style> 934 .wc-order-data-row .wc-order-totals:first-of-type tr:nth-of-type(2) { 935 display: none !important; 936 } 937 </style>'; 938 } 939 } 737 940 } 738 941 -
ceretax/trunk/inc/class-cwafc.php
r3285848 r3320210 81 81 // Woocommerce overide the plugin template. 82 82 add_filter( 'woocommerce_locate_template', array( $this, 'filter__cwafc_woo_adon_plugin_template' ), 10, 3 ); 83 // Add/Update order meta.84 add_action( 'woocommerce_checkout_update_order_meta', array( $this, 'action__cwafc_checkout_field_update_order_meta' ) );85 83 // Add tax calculation table on admin order edit page. 86 // add_action( 'woocommerce_admin_order_items_after_shipping', array( $this, 'action__cwafc_add_tax_calculation_table_after_shipping' ), 99 );87 84 add_action( 'add_meta_boxes', array( $this, 'action__cwafc_add_tax_calculation_table' ) ); 88 85 // Add tax calculation on order place. 89 86 add_action( 'woocommerce_new_order', array( $this, 'action__cwafc_add_tax_calculation_when_order_placed' ), 10, 2 ); 87 // Clear the session after order placed. 88 add_action( 'woocommerce_thankyou', array( $this, 'action__cwafc_clear_ceretax_session_after_order_placed' ), 10 ); 90 89 // Add tax calculation on subscription renewal order place. 91 90 add_filter( 'wcs_renewal_order_created', array( $this, 'filter__cwafc_add_tax_calculation_when_renewal_order_placed' ), 10 ); … … 105 104 // Clear Avatax from Ceretax renewal orders. 106 105 add_filter( 'wcs_new_order_created', array( $this, 'action__cwafc_clear_avatx_new_order_created' ), 10, 3 ); 106 // Include free fees in order totals. 107 add_filter( 'woocommerce_get_order_item_totals_excl_free_fees', '__return_false' ); 107 108 } 108 109 … … 121 122 return; 122 123 } 124 125 $order = wc_get_order( $order_id ); 126 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); 127 $has_cere_tax_fee = false; 128 129 // Check if the fee already exists in the order. 130 foreach ( $order->get_fees() as $fee ) { 131 if ( $fee->get_name() === $cere_tax_name ) { 132 $has_cere_tax_fee = true; 133 break; 134 } 135 } 136 137 // If the fee does not exist, return early. 138 if ( ! $has_cere_tax_fee ) { 139 return; 140 } 123 141 $ceretax_data = json_decode( $ceretax_data ); 124 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' );125 142 $total_tax_invoice = $ceretax_data->invoice->totalTaxInvoice; 126 $order = wc_get_order( $order_id );127 143 $fee_amount = null; 128 144 $order_total_fees = $order->get_total_fees(); 129 $order_remain_fees = 0;145 $order_remain_fees = null; 130 146 131 147 // If refunded order. … … 142 158 $order_remain_fees = (float) $order_total_fees - (float) $fee_amount; 143 159 } 144 $fee->save();145 160 break; 146 161 } 147 162 } 148 if ( 0 < $order_remain_fees) {163 if ( 0.0 !== $order_remain_fees && is_numeric( $order_remain_fees ) ) { 149 164 echo '<tr>'; 150 165 echo '<td class="label">' . esc_html( __( 'Fees', 'ceretax' ) ) . ':</td>'; 151 166 echo '<td width="1%"></td>'; 152 echo '<td class="total">' . w c_price( $order_remain_fees, array( 'currency' => $order->get_currency() ) ) . '</td>';167 echo '<td class="total">' . wp_kses_post( wc_price( $order_remain_fees, array( 'currency' => $order->get_currency() ) ) ) . '</td>'; 153 168 echo '</tr>'; 154 169 } … … 156 171 echo '<td class="label">' . esc_html( $cere_tax_name ) . ':</td>'; 157 172 echo '<td width="1%"></td>'; 158 echo '<td class="total">' . w c_price( $total_tax_invoice, array( 'currency' => $order->get_currency() ) ) . '</td>';173 echo '<td class="total">' . wp_kses_post( wc_price( $total_tax_invoice, array( 'currency' => $order->get_currency() ) ) ) . '</td>'; 159 174 echo '</tr>'; 160 175 } … … 268 283 $tax_rate = $this->cwafc_get_tax_rate_from_api( $address_1, $address_2, $country, $city, $state, $postcode ); 269 284 270 if ( ! empty( $tax_rate ) ) {285 if ( isset( $tax_rate ) && is_numeric( $tax_rate ) ) { 271 286 WC()->session->set( 'ceretax_rate', $tax_rate ); 272 287 wp_send_json_success(); … … 410 425 ); 411 426 412 if ( isset( $tax_rate ) && '' !== $tax_rate) {427 if ( isset( $tax_rate ) && is_numeric( $tax_rate ) ) { 413 428 WC()->session->set( 'ceretax_rate', $tax_rate ); 414 429 } … … 425 440 ob_start(); 426 441 wc_print_notice( $notice_msg, $notice_type ); 427 $notice = ob_get_clean(); 428 wp_send_json_success( 429 array( 430 'notice' => $notice, 431 'validatedAddress' => $validated_address_details, 432 ) 433 ); 442 $notice = ob_get_clean(); 443 $response_msg = array( 'notice' => $notice ); 444 if ( ! empty( $validated_address_details ) ) { 445 $response_msg['validatedAddress'] = $validated_address_details; 446 } 447 wp_send_json_success( $response_msg ); 434 448 } 435 449 … … 449 463 if ( empty( $custom_tax_rate ) ) { 450 464 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); 451 $tax_str = '<tr>465 $tax_str = '<tr> 452 466 <th>' . esc_html( $cere_tax_name ) . '</th> 453 467 <td data-title="Tax"> … … 465 479 * Calculate cart tax 466 480 * 481 * @param object $cart Cart object. 467 482 * @return mix 468 483 */ … … 478 493 479 494 $checkout_data = WC()->session->get( 'checkout_data' ); 480 481 $ceretax_stau = WC()->session->get( 'ceretax_stau' ); 495 $ceretax_stau = WC()->session->get( 'ceretax_stau' ); 482 496 483 497 // phpcs:disable WordPress.Security.NonceVerification.Missing 484 485 498 if ( is_cart() && isset( $_POST['calc_shipping'] ) ) { 486 499 … … 510 523 $calc_shipping_postcode, 511 524 ); 512 if ( isset( $tax_rate ) && '' !== $tax_rate) {525 if ( isset( $tax_rate ) && is_numeric( $tax_rate ) ) { 513 526 WC()->session->set( 'ceretax_rate', $tax_rate ); 514 527 } … … 522 535 $checkout_data['shipping_postcode'] 523 536 ); 524 if ( isset( $tax_rate ) && '' !== $tax_rate) {537 if ( isset( $tax_rate ) && is_numeric( $tax_rate ) ) { 525 538 WC()->session->set( 'ceretax_rate', $tax_rate ); 526 539 } … … 552 565 ); 553 566 554 if ( isset( $tax_rate ) && '' !== $tax_rate) {567 if ( isset( $tax_rate ) && is_numeric( $tax_rate ) ) { 555 568 WC()->session->set( 'ceretax_rate', $tax_rate ); 556 569 } 557 570 } 558 559 571 // phpcs:enable WordPress.Security.NonceVerification.Missing 572 560 573 $custom_tax_rate = WC()->session->get( 'ceretax_rate', 0 ); 561 574 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); 562 if ( ! empty( $custom_tax_rate ) ) { 575 576 if ( isset( $custom_tax_rate ) && is_numeric( $custom_tax_rate ) ) { 563 577 $tax = $custom_tax_rate; 564 578 … … 581 595 582 596 if ( class_exists( 'WC_Subscriptions_Product' ) && WC_Subscriptions_Product::is_subscription( $product_id ) ) { 583 $filtered = array_filter( $ceretax_tmp_items_data, function ( $filtered_item ) use ( $product_id ) { 584 return isset( $filtered_item->itemNumber ) && $filtered_item->itemNumber == $product_id; 585 }); 597 $filtered = array_filter( 598 $ceretax_tmp_items_data, 599 function ( $filtered_item ) use ( $product_id ) { 600 return isset( $filtered_item->itemNumber ) && $filtered_item->itemNumber == $product_id; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison, WordPress.NamingConventions.ValidVariableName 601 } 602 ); 586 603 $line_item_revenue_amount = ! empty( $filtered ) ? reset( $filtered )->revenue : 0; 587 604 $line_item_taxe_breaks = ! empty( $filtered ) ? reset( $filtered )->taxes : array(); … … 589 606 if ( ! empty( $line_item_taxe_breaks ) && is_array( $line_item_taxe_breaks ) ) { 590 607 foreach ( $line_item_taxe_breaks as $key => $val ) { 591 if ( ! empty( $val->calculationBaseAmt ) && ( $val->calculationBaseAmt >= $line_item_revenue_amount ) ) { 592 $line_item_calc_base_amount = $val->calculationBaseAmt; 593 $line_item_recurring_tax_amount += $val->totalTax; 608 if ( ! empty( $val->calculationBaseAmt ) && ( $val->calculationBaseAmt >= $line_item_revenue_amount ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName 609 $line_item_calc_base_amount = $val->calculationBaseAmt; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 610 $line_item_recurring_tax_amount += $val->totalTax; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 594 611 } 595 612 } … … 605 622 } 606 623 } else { 607 $cart->add_fee( $cere_tax_name, $tax, true, '' ); 608 } 609 // WC()->cart->add_fee( $cere_tax_name, $tax, true, '' ); 610 } elseif ( is_checkout() ) { 611 // Ensure the fee is added even if the tax is 0.00. 612 $tax = 0; 613 WC()->cart->add_fee( $cere_tax_name, $tax, true, '' ); 624 $cart->add_fee( $cere_tax_name, $tax, false ); 625 } 614 626 } 615 627 } … … 639 651 'state' => $order->get_shipping_state(), 640 652 'postcode' => $order->get_shipping_postcode(), 653 'country' => $order->get_shipping_country(), 641 654 ); 642 655 } else { … … 647 660 'state' => $order->get_billing_state(), 648 661 'postcode' => $order->get_billing_postcode(), 662 'country' => $order->get_billing_country(), 649 663 ); 650 664 } … … 712 726 'state' => $order->get_shipping_state(), 713 727 'postcode' => $order->get_shipping_postcode(), 728 'country' => $order->get_shipping_country(), 714 729 ); 715 730 } else { … … 720 735 'state' => $order->get_billing_state(), 721 736 'postcode' => $order->get_billing_postcode(), 737 'country' => $order->get_billing_country(), 722 738 ); 723 739 } … … 811 827 812 828 /** 813 * Add tax calculation table after shipping814 *815 * @param string $order_id Order ID.816 * @return void817 */818 public function action__cwafc_add_tax_calculation_table_after_shipping( $order_id ) {819 820 $ceretax_data = json_decode( get_post_meta( $order_id, 'ceretax_data', true ) );821 $tax_table = '';822 if ( is_object( $ceretax_data ) ) {823 $ceretax_items_data = $ceretax_data->invoice->lineItems;824 if ( ! empty( $ceretax_items_data ) ) {825 $tax_table .= '<tr><td colspan="7"><table class="ceratax-tax-table">';826 foreach ( $ceretax_items_data as $ceretax_item_data_key => $ceretax_item_data ) {827 if ( ! empty( $ceretax_item_data->taxes ) ) {828 $tax_table .= '<thead>829 <tr>830 <th>' . __( 'Authority', 'ceretax' ) . '</th>831 <th>' . __( 'Description', 'ceretax' ) . '</th>832 <th>' . __( 'Tax Type', 'ceretax' ) . '</th>833 <th>' . __( 'Tax Type Class', 'ceretax' ) . '</th>834 <th>' . __( 'Tax Type Ref', 'ceretax' ) . '</th>835 <th>' . __( 'Taxable', 'ceretax' ) . '</th>836 <th>' . __( 'Calc Base', 'ceretax' ) . '</th>837 <th>' . __( 'NonTaxable', 'ceretax' ) . '</th>838 <th>' . __( 'Exempt', 'ceretax' ) . '</th>839 <th>' . __( '% Taxable', 'ceretax' ) . '</th>840 <th>' . __( 'Tax rate', 'ceretax' ) . '</th>841 <th>' . __( 'Total Tax', 'ceretax' ) . '</th>842 </tr>843 <thead>';844 $tax_table .= '<tbody>';845 foreach ( $ceretax_item_data->taxes as $ceretax_item ) {846 // phpcs:disable847 $tax_table .= '<tr>848 <td>' . $ceretax_item->taxAuthorityName . '</td>849 <td>' . $ceretax_item->description . '</td>850 <td>' . $ceretax_item->taxTypeDesc . '</td>851 <td>' . $ceretax_item->taxTypeClassDesc . '</td>852 <td>' . $ceretax_item->taxTypeRefDesc . '</td>853 <td>' . $ceretax_item->taxable . '</td>854 <td>' . $ceretax_item->calculationBaseAmt . '</td>855 <td>' . $ceretax_item->nonTaxableAmount . '</td>856 <td>' . $ceretax_item->exemptAmount . '</td>857 <td>' . $ceretax_item->percentTaxable . '</td>858 <td>' . $ceretax_item->rate . '</td>859 <td>' . $ceretax_item->totalTax . '</td>860 </tr>';861 // phpcs:enable862 }863 $tax_table .= '</tbody>';864 }865 }866 $tax_table .= '</table></td></tr>';867 }868 }869 echo wp_kses_post( $tax_table );870 }871 872 /**873 829 * Add tax calculation table metaxbox. 874 830 * … … 878 834 global $post; 879 835 $ceretax_data = json_decode( get_post_meta( $post->ID, 'ceretax_data', true ) ); 880 if ( ! empty( $ceretax_data ) ) { 881 add_meta_box( 882 'cwafc_ceretax_metabox', 883 __( 'Ceretax Data', 'ceretax' ), 884 array( $this, 'cwafc_ceretax_metabox_callback' ), 885 array( 'shop_order', 'shop_subscription' ), 886 'normal', 887 'default' 888 ); 889 } 836 837 // If it's empty, return early. 838 if ( empty( $ceretax_data ) ) { 839 return; 840 } 841 842 $order = wc_get_order( $post->ID ); 843 // If the order does not exist, return early. 844 if ( ! $order ) { 845 return; 846 } 847 848 $cere_tax_name = get_option( CWAFC_PREFIX . '_cere_tax_name', 'Tax' ); 849 $has_cere_tax_fee = false; 850 851 // Check if the fee exists in the order. 852 foreach ( $order->get_fees() as $fee ) { 853 if ( $fee->get_name() === $cere_tax_name ) { 854 $has_cere_tax_fee = true; 855 break; 856 } 857 } 858 859 // If the fee does not exist, return early. 860 if ( ! $has_cere_tax_fee ) { 861 return; 862 } 863 864 add_meta_box( 865 'cwafc_ceretax_metabox', 866 __( 'Ceretax Data', 'ceretax' ), 867 array( $this, 'cwafc_ceretax_metabox_callback' ), 868 array( 'shop_order', 'shop_subscription' ), 869 'normal', 870 'default' 871 ); 890 872 } 891 873 … … 964 946 $order_ceretax_data = get_post_meta( $order_id, 'ceretax_data', true ); 965 947 $order_avatax_data = get_post_meta( $order_id, '_wc_avatax_tax_calculated', true ); 948 $traffic_source_data = get_post_meta( $order_id, '_traffic_source', true ); 966 949 // Check if order have other tax system. 967 950 if ( empty( $order_ceretax_data ) && ! empty( $order_avatax_data ) ) { 951 return false; 952 } 953 if ( ! empty( $traffic_source_data ) && 'meta_insta_shopify' === $traffic_source_data ) { 968 954 return false; 969 955 } … … 984 970 'state' => $order->get_shipping_state(), 985 971 'postcode' => $order->get_shipping_postcode(), 972 'country' => $order->get_shipping_country(), 986 973 ); 987 974 } else { … … 992 979 'state' => $order->get_billing_state(), 993 980 'postcode' => $order->get_billing_postcode(), 981 'country' => $order->get_billing_country(), 994 982 ); 995 983 } … … 998 986 $res = $this->cwafc_calculate_cere_tax( $address_data, $order ); 999 987 } 1000 1001 if ( is_admin() && ! empty( $res ) ) { 988 if ( isset( $res ) && is_numeric( $res ) ) { 1002 989 $fee_exists = false; 1003 990 foreach ( $order->get_fees() as $fee ) { … … 1022 1009 // Recalculate order totals. 1023 1010 $order->calculate_totals(); 1011 do_action( 'woocommerce_order_after_calculate_totals', $order->get_id(), $order ); 1024 1012 // Save the order. 1025 1013 $order->save(); 1026 1014 } 1015 } 1016 1017 /** 1018 * Add address validation button on checkout page. 1019 * 1020 * @return void 1021 */ 1022 public function action__cwafc_clear_ceretax_session_after_order_placed() { 1023 WC()->session->__unset( 'ceretax_rate' ); 1024 WC()->session->__unset( 'ceretax_stau' ); 1025 WC()->session->__unset( 'checkout_data' ); 1027 1026 } 1028 1027 … … 1038 1037 $order_ceretax_data = get_post_meta( $renewal_order->get_id(), 'ceretax_data', true ); 1039 1038 $order_avatax_data = get_post_meta( $renewal_order->get_id(), '_wc_avatax_tax_calculated', true ); 1039 $traffic_source_data = get_post_meta( $renewal_order->get_id(), '_traffic_source', true ); 1040 1040 $order_contains_renewal = ( function_exists( 'wcs_order_contains_renewal' ) ) ? wcs_order_contains_renewal( $renewal_order->get_id() ) : true; 1041 1041 // Check if order have other tax system. 1042 1042 if ( empty( $order_ceretax_data ) && ! empty( $order_avatax_data ) && ! $order_contains_renewal ) { 1043 1043 return $renewal_order; 1044 } 1045 if ( ! empty( $traffic_source_data ) && 'meta_insta_shopify' === $traffic_source_data ) { 1046 return false; 1044 1047 } 1045 1048 if ( 'yes' !== $cere_tax_post_transactions ) { … … 1057 1060 'state' => $r_order->get_shipping_state(), 1058 1061 'postcode' => $r_order->get_shipping_postcode(), 1062 'country' => $r_order->get_shipping_country(), 1059 1063 ); 1060 1064 } else { … … 1065 1069 'state' => $r_order->get_billing_state(), 1066 1070 'postcode' => $r_order->get_billing_postcode(), 1071 'country' => $r_order->get_billing_country(), 1067 1072 ); 1068 1073 } … … 1071 1076 $res = $this->cwafc_calculate_cere_tax( $address_data, $r_order ); 1072 1077 } 1073 1074 if ( isset( $res ) && null !== $res ) { 1078 if ( isset( $res ) && is_numeric( $res ) ) { 1075 1079 $fee_exists = false; 1076 1080 foreach ( $r_order->get_fees() as $fee ) { … … 1110 1114 */ 1111 1115 public function action__cwafc_order_after_calculate_totals( $and_taxes, $order ) { 1112 1113 1116 // Check static flag first. 1114 1117 if ( self::$is_calculating ) { … … 1121 1124 $order_ceretax_data = get_post_meta( $order->get_id(), 'ceretax_data', true ); 1122 1125 $order_avatax_data = get_post_meta( $order->get_id(), '_wc_avatax_tax_calculated', true ); 1126 $traffic_source_data = get_post_meta( $order->get_id(), '_traffic_source', true ); 1127 1123 1128 // Check if order have other tax system. 1124 1129 if ( empty( $order_ceretax_data ) && ! empty( $order_avatax_data ) ) { 1125 1130 return false; 1126 1131 } 1132 1133 if ( ! empty( $traffic_source_data ) && 'meta_insta_shopify' === $traffic_source_data ) { 1134 return false; 1135 } 1136 1127 1137 // Check order if refunded. 1128 1138 if ( $order instanceof WC_Order_Refund || 'refunded' === $order->get_status() ) { 1129 1139 return false; 1130 1140 } 1141 1131 1142 if ( 'yes' !== $cere_tax_post_transactions ) { 1132 1143 return false; 1133 1144 } 1145 1134 1146 // Check for paid order. 1135 1147 if ( $order && $order->is_paid() ) { … … 1145 1157 'state' => $order->get_shipping_state(), 1146 1158 'postcode' => $order->get_shipping_postcode(), 1159 'country' => $order->get_shipping_country(), 1147 1160 ); 1148 1161 } else { … … 1153 1166 'state' => $order->get_billing_state(), 1154 1167 'postcode' => $order->get_billing_postcode(), 1168 'country' => $order->get_billing_country(), 1155 1169 ); 1156 1170 } … … 1160 1174 $res = $this->cwafc_calculate_cere_tax( $address_data, $order ); 1161 1175 } 1162 1163 if ( ! empty( $res ) ) { 1176 if ( isset( $res ) && is_numeric( $res ) ) { 1164 1177 $fee_exists = false; 1165 1178 foreach ( $order->get_fees() as $fee ) { … … 1182 1195 $order->add_item( $item_fee ); 1183 1196 } 1184 // Set the transient to prevent recursion.1185 // set_transient( 'prevent_order_calculate_totals', true, 10 );1186 1187 1197 // Recalculate order totals. 1188 1198 $order->calculate_totals(); 1189 1199 1190 // Remove the transient after recalculation.1191 // delete_transient( 'prevent_order_calculate_totals' );1192 1193 1200 // Save the order. 1194 1201 $order->save(); … … 1209 1216 $order = wc_get_order( $order_id ); 1210 1217 $refund = wc_get_order( $refund_id ); 1218 1219 $traffic_source_data = get_post_meta( $order_id, '_traffic_source', true ); 1220 if ( ! empty( $traffic_source_data ) && 'meta_insta_shopify' === $traffic_source_data ) { 1221 return false; 1222 } 1211 1223 1212 1224 // Save ceretax line item tax in order line items. … … 1216 1228 $line_item_json = stripslashes( sanitize_text_field( wp_unslash( $_POST['line_item_tax_totals'] ) ) ); 1217 1229 $line_item_data = json_decode( $line_item_json, true ); 1218 $line_item_result = array_map( function( $item ) { 1219 return $item['undefined']; 1220 }, $line_item_data ); 1221 $line_item_result = array_filter( $line_item_result, function( $value ) { 1222 return ! empty( $value ); 1223 }); 1230 $line_item_result = array_map( 1231 function ( $item ) { 1232 return $item['undefined']; 1233 }, 1234 $line_item_data 1235 ); 1236 $line_item_result = array_filter( 1237 $line_item_result, 1238 function ( $value ) { 1239 return ! empty( $value ); 1240 } 1241 ); 1224 1242 1225 1243 // For order items. … … 1266 1284 'state' => $order->get_shipping_state(), 1267 1285 'postcode' => $order->get_shipping_postcode(), 1286 'country' => $order->get_shipping_country(), 1268 1287 ); 1269 1288 } else { … … 1274 1293 'state' => $order->get_billing_state(), 1275 1294 'postcode' => $order->get_billing_postcode(), 1295 'country' => $order->get_billing_country(), 1276 1296 ); 1277 1297 } … … 1280 1300 $res = $this->cwafc_calculate_cere_tax_refunded( $address_data, $refund, $order ); 1281 1301 } 1282 1283 1302 $is_run = false; 1284 if ( $is_run && ! empty( $res ) ) {1303 if ( $is_run && isset( $res ) && is_numeric( $res ) ) { 1285 1304 $fee_exists = false; 1286 1305 foreach ( $order->get_fees() as $fee ) { … … 1370 1389 } 1371 1390 1391 // Get store address. 1392 $store_address = get_option( 'woocommerce_store_address' ); 1393 $store_address2 = get_option( 'woocommerce_store_address_2' ); 1394 $store_city = get_option( 'woocommerce_store_city' ); 1395 $store_postcode = get_option( 'woocommerce_store_postcode' ); 1396 $store_default_country = get_option( 'woocommerce_default_country' ); 1397 1398 // Get country and state separately. 1399 list( $store_country, $store_state ) = array_pad( explode( ':', $store_default_country ), 2, '' ); 1400 1372 1401 // Caclulate tax if only CereTax calculation option is not enabled. 1373 1402 if ( ! $this->cwafc_is_ceretax_enable() ) { … … 1385 1414 $item_count = 0; 1386 1415 $order_status = $order->get_status(); 1387 $created_via = $order->get_ meta( '_created_via');1416 $created_via = $order->get_created_via(); 1388 1417 $order_parent_id = $order->get_parent_id(); 1389 1418 $order_type = $order->get_type(); … … 1440 1469 ), 1441 1470 'situs' => array( 1442 'taxSitusRule' => 'T', 1443 'shipToAddress' => array( 1471 'taxSitusRule' => 'T', 1472 'shipFromAddress' => array( 1473 'addressLine1' => $store_address, 1474 'addressLine2' => $store_address2, 1475 'city' => $store_city, 1476 'state' => $store_state, 1477 'postalCode' => $store_postcode, 1478 'country' => $store_country, 1479 'validateAddress' => $cere_tax_validate_address_on_transaction, 1480 ), 1481 'shipToAddress' => array( 1444 1482 'addressLine1' => $address_data['address_1'], 1445 1483 'addressLine2' => $address_data['address_2'], … … 1447 1485 'state' => $address_data['state'], 1448 1486 'postalCode' => $address_data['postcode'], 1487 'country' => $address_data['country'], 1449 1488 'validateAddress' => $cere_tax_validate_address_on_transaction, 1450 1489 ), … … 1471 1510 ); 1472 1511 } 1473 $item_count++; 1512 $item_count++; // phpcs:ignore Generic.CodeAnalysis.UnusedIncrement, WordPress.PHP.PreIncrement.PreIncrement 1474 1513 } 1475 1514 … … 1518 1557 1519 1558 $ceretax_stau = get_post_meta( $order->get_id(), 'ceretax_stau_' . $order->get_id(), true ); 1520 1521 // if ( ( empty( $ceretax_stau ) || 'not_found' === $ceretax_stau ) && ! empty( $body ) && ! empty( $cere_tax_api_key ) ) {1522 1559 if ( empty( $ceretax_stau ) && ! empty( $body ) && ! empty( $cere_tax_api_key ) ) { 1523 1524 1560 $response = wp_remote_post( 1525 1561 $api_url, … … 1570 1606 $order_line_item_count = get_post_meta( $order->get_id(), 'ceretax_order_line_item_count', true ); 1571 1607 1572 if ( 'true' === $wps_upsell_order_started && 'true' !== $wps_separate_upsell_order && $order_line_item_count != count( $order->get_items() ) ) {1608 if ( 'true' === $wps_upsell_order_started && 'true' !== $wps_separate_upsell_order && count( $order->get_items() ) != $order_line_item_count ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison 1573 1609 1574 1610 update_post_meta( $order->get_id(), 'wps_separate_upsell_order', 'true' ); … … 1611 1647 1612 1648 } else { 1613 1614 1649 $response = wp_remote_post( 1615 1650 $api_url . '?systemTraceAuditNumber=' . $ceretax_stau, … … 1701 1736 } 1702 1737 1738 // Get store address. 1739 $store_address = get_option( 'woocommerce_store_address' ); 1740 $store_address2 = get_option( 'woocommerce_store_address_2' ); 1741 $store_city = get_option( 'woocommerce_store_city' ); 1742 $store_postcode = get_option( 'woocommerce_store_postcode' ); 1743 $store_default_country = get_option( 'woocommerce_default_country' ); 1744 1745 // Get country and state separately. 1746 list( $store_country, $store_state ) = array_pad( explode( ':', $store_default_country ), 2, '' ); 1747 1703 1748 // Caclulate tax if only CereTax calculation option is not enabled. 1704 1749 if ( ! $this->cwafc_is_ceretax_enable() ) { … … 1714 1759 $item_count = 0; 1715 1760 $order_status = $order->get_status(); 1716 $created_via = $order->get_ meta( '_created_via');1761 $created_via = $order->get_created_via(); 1717 1762 $order_parent_id = $order->get_parent_id(); 1718 1763 $order_type = $order->get_type(); … … 1758 1803 ), 1759 1804 'situs' => array( 1760 'taxSitusRule' => 'T', 1761 'shipToAddress' => array( 1805 'taxSitusRule' => 'T', 1806 'shipFromAddress' => array( 1807 'addressLine1' => $store_address, 1808 'addressLine2' => $store_address2, 1809 'city' => $store_city, 1810 'state' => $store_state, 1811 'postalCode' => $store_postcode, 1812 'country' => $store_country, 1813 'validateAddress' => $cere_tax_validate_address_on_transaction, 1814 ), 1815 'shipToAddress' => array( 1762 1816 'addressLine1' => $address_data['address_1'], 1763 1817 'addressLine2' => $address_data['address_2'], … … 1765 1819 'state' => $address_data['state'], 1766 1820 'postalCode' => $address_data['postcode'], 1821 'country' => $address_data['country'], 1767 1822 'validateAddress' => $cere_tax_validate_address_on_transaction, 1768 1823 ), … … 1789 1844 ); 1790 1845 } 1791 $item_count++; 1846 $item_count++; // phpcs:ignore WordPress.PHP.PreIncrement.PreIncrement 1792 1847 } 1793 1848 … … 1936 1991 $shipping_zones = WC_Shipping_Zones::get_zones(); 1937 1992 1993 // Get store address. 1994 $store_address = get_option( 'woocommerce_store_address' ); 1995 $store_address2 = get_option( 'woocommerce_store_address_2' ); 1996 $store_city = get_option( 'woocommerce_store_city' ); 1997 $store_postcode = get_option( 'woocommerce_store_postcode' ); 1998 $store_default_country = get_option( 'woocommerce_default_country' ); 1999 2000 // Get country and state separately. 2001 list( $store_country, $store_state ) = array_pad( explode( ':', $store_default_country ), 2, '' ); 2002 1938 2003 // Caclulate tax if only CereTax calculation option is not enabled. 1939 2004 if ( ! $this->cwafc_is_ceretax_enable() ) { … … 2004 2069 ), 2005 2070 'situs' => array( 2006 'taxSitusRule' => 'T', 2007 'shipToAddress' => array( 2071 'taxSitusRule' => 'T', 2072 'shipFromAddress' => array( 2073 'addressLine1' => $store_address, 2074 'addressLine2' => $store_address2, 2075 'city' => $store_city, 2076 'state' => $store_state, 2077 'postalCode' => $store_postcode, 2078 'country' => $store_country, 2079 'validateAddress' => $cere_tax_validate_address_on_transaction, 2080 ), 2081 'shipToAddress' => array( 2008 2082 'addressLine1' => $shipping_address_1, 2009 2083 'addressLine2' => $shipping_address_2, … … 2011 2085 'state' => $state, 2012 2086 'postalCode' => $postcode, 2087 'country' => $country, 2013 2088 'validateAddress' => $cere_tax_validate_address_on_transaction, 2014 2089 ), … … 2094 2169 2095 2170 if ( 200 === wp_remote_retrieve_response_code( $response ) ) { 2096 WC()->session->set( 'ceretax_data', $data );2097 2171 return $data['invoice']['totalTaxInvoice']; 2098 2172 } … … 2132 2206 2133 2207 if ( isset( $data['invoice']['totalTaxInvoice'] ) ) { 2134 WC()->session->set( 'ceretax_data', $data );2135 2208 return $data['invoice']['totalTaxInvoice']; 2136 2209 } … … 2162 2235 // Caclulate tax if only CereTax calculation option is not enabled. 2163 2236 $cere_tax_enable = get_option( CWAFC_PREFIX . '_cere_tax_enable' ); 2164 return 'yes' === $cere_tax_enable ? true : false; 2237 return 'yes' === $cere_tax_enable ? true : false; 2165 2238 } 2166 2239 … … 2258 2331 public function action__cwafc_clear_avatx_new_order_created( $order, $subscription, $type ) { 2259 2332 2260 if ( ! class_exists( 'WC_AvaTax_Order_Handler' ) && ! empty( $subscription->get_meta( '_wc_avatax_tax_calculated' ) ) && $subscription->get_meta( '_wc_avatax_tax_calculated' ) == 'yes'&& empty( $order->get_meta( '_wc_avatax_tax_calculated' ) ) ) {2333 if ( ! class_exists( 'WC_AvaTax_Order_Handler' ) && ! empty( $subscription->get_meta( '_wc_avatax_tax_calculated' ) ) && 'yes' == $subscription->get_meta( '_wc_avatax_tax_calculated' ) && empty( $order->get_meta( '_wc_avatax_tax_calculated' ) ) ) { 2261 2334 2262 2335 // Clear avatax data from order item meta. … … 2296 2369 } 2297 2370 } 2298 if ( $require_recalculation == 1 ) {2371 if ( 1 == $require_recalculation ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison 2299 2372 $order->save(); 2300 2373 $order->calculate_totals(); … … 2306 2379 } 2307 2380 2308 /**2309 * CWAFC create function to return instance.2310 *2311 * @return object2312 */2313 2381 if ( ! function_exists( 'cwafc' ) ) { 2382 /** 2383 * CWAFC create function to return instance. 2384 * 2385 * @return object 2386 */ 2314 2387 function cwafc() { 2315 2388 return CWAFC::get_instance(); -
ceretax/trunk/readme.txt
r3285848 r3320210 3 3 Tags: sales tax, taxes, tax, tax calculation, sales tax compliance 4 4 Requires at least: 4.0.1 5 Tested up to: 6. 6.15 Tested up to: 6.8.1 6 6 Requires PHP: 7.4 7 Stable tag: 1.4. 27 Stable tag: 1.4.3 8 8 License: GNU General Public License v3.0 9 9 URI: http://www.gnu.org/licenses/gpl-3.0.html 10 10 WC requires at least: 7.0.0 11 WC tested up to: 9. 2.011 WC tested up to: 9.9.5 12 12 13 13 Simplify sales tax complexity with CereTax for WooCommerce. … … 35 35 36 36 == Changelog == 37 38 = 1.4.3 = 39 * fix - Resolved PHP warning errors 40 * add - Included 'shipFromAddress' parameter in the ceretax API request 37 41 38 42 = 1.4.2 = … … 90 94 == Upgrade Notice == 91 95 96 = 1.4.3 = 97 * fix - Resolved PHP warning errors 98 * add - Included 'shipFromAddress' parameter in the ceretax API request 99 92 100 = 1.4.2 = 93 101 * fix - Tax box now hidden in refunds to avoid confusion, as it no longer reflects accurate post-refund data -
ceretax/trunk/woocommerce/cart/shipping-calculator.php
r3219747 r3320210 13 13 * @see https://woocommerce.com/document/template-structure/ 14 14 * @package WooCommerce\Templates 15 * @version 7.0.115 * @version 9.7.0 16 16 */ 17 17
Note: See TracChangeset
for help on using the changeset viewer.