admin_url( 'admin-ajax.php' ),
'plugin_dir_url' => plugin_dir_url( __FILE__ ),
'rendelesi_azonosito' => __('Order ID:', 'allpacka' ),
'fuvarlevelszam' => __('Waybill number:', 'allpacka' ),
'ugyfelszolgalat_kuldi' => __('The waybill will be sent to you by the Allpacka.com Customer Service.', 'allpacka' ),
'megtekintes' => __('View', 'allpacka' ),
'nyomkovetes' => __('Tracking', 'allpacka' ),
);
wp_localize_script( 'allpacka_admin_js', 'allpacka_adatok', $allpacka_adatok );
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
add_action( 'wp_enqueue_scripts', 'allpacka_mask_js' );
function allpacka_mask_js() {
wp_enqueue_script( 'allpacka_frontend_js', plugins_url('js/frontend.js', __FILE__) );
wp_enqueue_script( 'allpacka_mask1', plugins_url('js/inputmask.js', __FILE__), '', null, false );
wp_enqueue_script( 'allpacka_mask2', plugins_url('js/jquery.inputmask.js', __FILE__), '', null, false );
wp_enqueue_script( 'allpacka_mask3', plugins_url('js/inputmask.numeric.extensions.js', __FILE__), '', null, false );
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
add_action( 'admin_enqueue_scripts', 'allpacka_admin_css' );
function allpacka_admin_css() {
wp_enqueue_style( 'allpacka_admin_css', plugins_url('css/admin.css', __FILE__) );
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
register_activation_hook( __FILE__, 'allpacka_mappa' );
function allpacka_mappa(){
$upload_dir = wp_upload_dir();
if (!is_dir( $upload_dir['basedir'].'/allpacka' )) {
mkdir( $upload_dir['basedir'].'/allpacka', 0777, true );
}
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
add_filter('manage_edit-shop_order_columns' , 'allpacka_order_column_title', 10);
function allpacka_order_column_title( $columns ) {
if( get_option( 'allpacka_allapot' ) == 'yes' ){
$columns['allpacka'] = '
Allpacka.com';
}
return $columns;
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
add_action('manage_shop_order_posts_custom_column' , 'allpacka_order_column', 10, 2 );
function allpacka_order_column( $column_name, $order_id ) {
if( get_option( 'allpacka_allapot' ) == 'yes' ){
switch ( $column_name ) {
case 'allpacka' :
allpacka_gombok( $order_id );
break;
}
}
}
/**********************************************************************************************************************************************************************/
/**********************************************************************************************************************************************************************/
function allpacka_gombok( $order_id ){
$upload_dir = wp_upload_dir();
$allpacka_azonosito = get_post_meta( $order_id, '_allpacka_azonosito', true );
$allpacka_fuvarlevelszam = get_post_meta( $order_id, '_allpacka_fuvarlevelszam', true );
if( empty( $allpacka_azonosito ) && empty( $allpacka_fuvarlevelszam ) ){
echo ''.__( 'Place order', 'allpacka' ).'';
}
else if( !empty( $allpacka_azonosito ) && empty( $allpacka_fuvarlevelszam ) ){
echo '
'.__( 'Order ID:', 'allpacka' ).' '.$allpacka_azonosito.'
'; echo '
'.__( 'The waybill will be sent to you by the Allpacka.com Customer Service.', 'allpacka' ).'
'.__( 'Order ID:', 'allpacka' ).' '.$allpacka_azonosito.'
'; echo ''; echo ''.__( 'Waybill number:', 'allpacka' ).' '.$allpacka_fuvarlevelszam.''; if( file_exists( $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$allpacka_fuvarlevelszam.'.pdf' ) ){ echo ''; } if( $nyomkovetes_url = allpacka_nyomkovetes_url( $allpacka_fuvarlevelszam ) ){ echo ''; } echo '
'; } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_nyomkovetes_url( $allpacka_fuvarlevelszam ){ if( strlen( $allpacka_fuvarlevelszam ) == 11 && substr( $allpacka_fuvarlevelszam, 0, 3) == '002' ){ $nyelv_kod = allpacka_nyelv(); if( $nyelv_kod == 'RO' ){ return 'https://gls-group.eu/RO/ro/urmarire-colet?match='.$allpacka_fuvarlevelszam; } else{ return 'https://gls-group.eu/HU/en/parcel-tracking?match='.$allpacka_fuvarlevelszam; } } else if( strlen( $allpacka_fuvarlevelszam ) == 14 && substr( $allpacka_fuvarlevelszam, 0, 3) == '164' ){ $nyelv_kod = allpacka_nyelv(); if( $nyelv_kod == 'RO' ){ return 'https://tracking.dpd.de/parcelstatus?query='.$allpacka_fuvarlevelszam.'&locale=ro_RO'; } else{ return 'https://tracking.dpd.de/parcelstatus?query='.$allpacka_fuvarlevelszam.'&locale=en_HU'; } } else{ return false; } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_action("add_meta_boxes", "allpacka_order_meta_box"); function allpacka_order_meta_box(){ if( get_option( 'allpacka_allapot' ) == 'yes' ){ add_meta_box("allpacka_meta_box", '', 'allpacka_order_meta_box_content', 'shop_order', 'side', 'high', null); } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_order_meta_box_content( $order ){ if( get_option( 'allpacka_allapot' ) == 'yes' ){ if( !empty( $order->ID ) ){ allpacka_gombok( $order->ID ); } } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_konvertalas( $string ){ if( $string == 'yes' ){ return 'true'; } else{ return 'false'; } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ function allpacka_nyelv(){ $locale = get_locale(); if( $locale && substr( $locale, 0, 2 ) == 'ro' ){ return 'RO'; } else if( $locale && substr( $locale, 0, 2 ) == 'en' ){ return 'EN'; } else{ return 'EN'; } } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_filter( 'woocommerce_settings_tabs_array', 'allpacka_add_settings_tab', 50 ); function allpacka_add_settings_tab( $settings_tabs ) { $settings_tabs['allpacka'] = 'Allpacka.com'; return $settings_tabs; } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_action( 'woocommerce_settings_tabs_allpacka', 'allpacka_settings_tab' ); function allpacka_settings_tab() { echo ''.__( 'Request sent to Allpacka.com:', 'allpacka' ).'
'.print_r( $JSON, true ).''; } $JSON = json_encode( $JSON ); $options = array( 'http' => array( 'method' => 'POST', 'content' => $JSON ) ); $url = 'https://allpacka.com/webservices/webshop2.ashx'; $context = stream_context_create( $options ); $result = file_get_contents( $url, false, $context ); $result = json_decode( $result, true); if( get_option( 'allpacka_debug' ) == 'yes' ){ $return['result'] = '
'.__( 'Response received from Allpacka.com:', 'allpacka' ).'
'.print_r( $result, true ).''; } if( get_option( 'allpacka_tesztkornyezet' ) == 'yes' ){ if( $result ){ if( $result['Messages'] ){ foreach( $result['Messages'] as $message ){ if( $message['Text'] != 'TEST: Quote added successfully' ){ $return['hiba'][] = ''.__( 'Error message from Allpacka.com:', 'allpacka' ).' '.$message['Text']; } } } if( !empty( $result['Order']['Labels'] ) && !empty( $result['Order']['WayBills'] ) ){ update_post_meta( $order_id, '_allpacka_azonosito', 'teszt_'.$order_id ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', $result['Order']['WayBills'][0] ); $return['azonosito'] = $result['Order']['ID']; $return['fuvarlevelszam'] = $result['Order']['WayBills'][0]; $minta_fuvarlevel = plugin_dir_url(__FILE__).'/pdf/minta_fuvarlevel.pdf'; $upload_dir = wp_upload_dir(); $fajlnev_dir = $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$result['Order']['WayBills'][0].'.pdf'; $fajlnev_url = $upload_dir['baseurl'].'/allpacka/waybill_'.$order_id.'_'.$result['Order']['WayBills'][0].'.pdf'; copy( $minta_fuvarlevel, $fajlnev_dir); $return['siker'] = __( 'Successful Allpacka.com order. Webshop order ID:', 'allpacka' ).' '.$order_id.'. '.__( 'Allpacka.com order ID:', 'allpacka' ).' '.$result['Order']['ID'].'. '.__( 'Fuvarlevélszám:', 'allpacka' ).' '.$result['Order']['WayBills'][0].'. '.__( 'The waybill contains fake data in test mode!', 'allpacka' ).''; $return['fajlnev_url'] = $fajlnev_url; $return['nyomkovetes_url'] = allpacka_nyomkovetes_url( $result['Order']['WayBills'][0] ); $order->add_order_note( sprintf( __( 'Successful Allpacka.com order. Allpacka.com order ID: %s. Waybill number: %s. The waybill contains fake data in test mode!', 'allpacka' ), $result['Order']['ID'], $result['Order']['WayBills'][0] ) ); } else{ $return['hiba'][] = ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'Unsuccesful Allpacka.com order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id; $order->add_order_note( ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'Unsuccesful Allpacka.com order.', 'allpacka' ) ); } } else{ $return['hiba'][] = ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'No response received from Allpacka.com for the request.', 'allpacka' ) .' '. __('Password or email address probably wrong.', 'allpacka' ); $order->add_order_note( ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'No response received from Allpacka.com for the request.', 'allpacka' ) ); } } else{ if( $result ){ if( $result['Messages'] ){ foreach( $result['Messages'] as $message ){ $return['hiba'][] = ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.$message['Text']; } } if( $result['Order']['ID'] > 0 && empty( $result['Order']['Labels'] ) && empty( $result['Order']['WayBills'] ) ){ update_post_meta( $order_id, '_allpacka_azonosito', $result['Order']['ID'] ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', '' ); $return['azonosito'] = $result['Order']['ID']; $return['siker_2'] = __( 'Successful Allpacka.com order, but a label/waybill was not generated. The Customer Service of Allpacka.com corrects the mistake and sends you an email.', 'allpacka' ).' '.__('Webshop order ID:', 'allpacka' ).' '.$order_id.'. '.__( 'Allpacka.com order ID:', 'allpacka' ).' '.$result['Order']['ID'].'.'; $order->add_order_note( __( 'Successful Allpacka.com order, but a label/waybill was not generated. The Customer Service of Allpacka.com corrects the mistake and sends you an email.', 'allpacka' )); } else if( !empty( $result['Order']['Labels'] ) && !empty( $result['Order']['WayBills'] ) && $result['Order']['ID'] > 0 ){ $fuvarlevel = $result['Order']['Labels'][0]; if( !empty( $fuvarlevel ) ){ update_post_meta( $order_id, '_allpacka_azonosito', $result['Order']['ID'] ); update_post_meta( $order_id, '_allpacka_fuvarlevelszam', $result['Order']['WayBills'][0] ); $return['azonosito'] = $result['Order']['ID']; $return['fuvarlevelszam'] = $result['Order']['WayBills'][0]; $upload_dir = wp_upload_dir(); $fuvarlevel = base64_decode($fuvarlevel); $fajlnev_dir = $upload_dir['basedir'].'/allpacka/waybill_'.$order_id.'_'.$result['Order']['WayBills'][0].'.pdf'; $fajlnev_url = $upload_dir['baseurl'].'/allpacka/waybill_'.$order_id.'_'.$result['Order']['WayBills'][0].'.pdf'; file_put_contents( $fajlnev_dir, $fuvarlevel); $return['siker'] = __( 'Successful Allpacka.com order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id.'. '. __( 'Allpacka.com order ID:', 'allpacka' ) . ' '.$result['Order']['ID'].'. '. __( 'Waybill number:', 'allpacka' ).' '.$result['Order']['WayBills'][0].'.'; $return['fajlnev_url'] = $fajlnev_url; $return['nyomkovetes_url'] = allpacka_nyomkovetes_url( $result['Order']['WayBills'][0] ); $order->add_order_note( sprintf( __( 'Successful Allpacka.com order. Allpacka.com order ID: %s. Waybill number: %s.', 'allpacka' ), $result['Order']['ID'], $result['Order']['WayBills'][0] ) ); } else{ $return['hiba'][] = ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'Unsuccesful Allpacka.com order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id; $order->add_order_note( ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'Unsuccesful Allpacka.com order.', 'allpacka' ) ); } } else{ $return['hiba'][] = ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'Unsuccesful Allpacka.com order.', 'allpacka' ).' '.__( 'Webshop order ID:', 'allpacka' ).' '.$order_id; $order->add_order_note( ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'Unsuccesful Allpacka.com order.', 'allpacka' ) ); } } else{ $return['hiba'][] = ''.__( 'Allpacka.com error message:', 'allpacka' ).' ' . __( 'No response received from Allpacka.com for the ORDER request.', 'allpacka' ) . ' ' . __( 'Password or email address probably wrong.', 'allpacka' ); $order->add_order_note( ''.__( 'Allpacka.com error message:', 'allpacka' ).' '.__( 'No response received from Allpacka.com for the ORDER request.', 'allpacka' ) ); } } echo json_encode( $return ); } die(); } add_action( 'wp_ajax_allpacka_megrendeles', 'allpacka_megrendeles' ); add_action( 'wp_ajax_nopriv_allpacka_megrendeles', 'allpacka_megrendeles' ); /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ add_filter( 'woocommerce_checkout_fields' , 'allpacka_add_field_and_reorder_fields' ); function allpacka_add_field_and_reorder_fields( $fields ) { $fields['billing']['billing_houseno'] = array( 'label' => __('House number', 'allpacka'), 'placeholder' => __('19/B', 'allpacka'), 'required' => true, 'class' => array('form-row-first'), 'clear' => false ); $fields['shipping']['shipping_houseno'] = array( 'label' => __('House number', 'allpacka'), 'placeholder' => __('19/B', 'allpacka'), 'required' => true, 'class' => array('form-row-first'), 'clear' => false ); return $fields; } /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ /**********************************************************************************************************************************************************************/ ?>