Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige emissão automática de NF #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions init-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function __construct(){
function hooks(){

add_filter( 'woocommercenfe_plugins_url', array($this, 'default_plugin_url') );
add_action( 'transition_post_status', array($this, 'issue_automatic_invoice'), 10, 4 );
add_action( 'woocommerce_order_status_changed', array($this, 'issue_automatic_invoice'), 10, 4 );
add_filter( "plugin_action_links_".plugin_basename( __FILE__ ), array($this, 'plugin_add_settings_link') );
do_action( 'woocommercenfe_loaded' );

Expand Down Expand Up @@ -258,28 +258,21 @@ function add_success( $message ){
*
* @return void
*/
function issue_automatic_invoice( $to, $from, $post ) {

// Validations
if (get_post_type($post) != 'shop_order')
return;
function issue_automatic_invoice( $order_id, $from, $to, $order ) {

$option = apply_filters( 'nfe_issue_automatic', get_option('wc_settings_woocommercenfe_emissao_automatica') );
if ( !$option ){
return;
}

// Vars
$order_id = $post->ID;
$order = wc_get_order( $order_id );
$response = null;

// Process
if (
$to == 'wc-processing' && ($option == 1 || $option == 'yes') ||
$to == 'wc-completed' && $option == 2
$to == 'processing' && ($option == 1 || $option == 'yes') ||
$to == 'completed' && $option == 2
){

$nfes = get_post_meta( $order->id, 'nfe', true );
$nfes = $order->get_meta( 'nfe', true );

if ( !empty($nfes) && is_array($nfes) ) {
foreach ( $nfes as $nfe ) {
Expand Down