# Χρήσιμα filters

### Βάρος

Στο παρακάτω παράδειγμα ορίζουμε μέγιστο βάρος τα 2 κιλά εάν είναι πάνω απο 2, διαφορετικά θα πάρει το βάρος που έχει αυτόματα υπολογιστεί από τα προϊόντα

<pre class="language-php"><code class="lang-php">function ibeb_acs_myweight($weight){
if ($weight > 2){
    $newweight = 2;
}else{
    $newweight = $weight;
}
<strong> 
</strong>return $newweight;
}
 
add_filter( 'iben_acs_filter_weight_order_metabox', 'ibeb_acs_myweight' );
</code></pre>

### Τηλέφωνο 2 ή κινητό σε custom πεδίο

Εαν έχετε custom πεδίο στο checkout, πχ Κινητό και meta name είναι \_billing\_mobile κανένα πρόβλημα.

Σε άλλη περίπτωση εαν το custom πεδίο σας έχει διαφορετικό meta name τότε θα πρέπει να τρέξετε το παρακάτω κώδικα στο αρχείο chilld  functions.php και απλά αλλάξτε το όνομα **\_billing\_mobile** με το δικό σας meta όνομα.

Η κάτω παύλα ( \_ ) είναι απαραίτητη.

<br>

```php
function ben_acs_mycustomphonefield(){ 
  return '_billing_mobile';
}
 
add_filter( 'iben_acs_filter_phone2_metafield_order_metabox', 'ben_acs_mycustomphonefield' );
```

### Άλλα filters

`iben_acs_filter_comments_order_metabox`

Για τα σχόλια / παρατηρήσεις του voucher

`iben_acs_filter_cashdelivery_order_metabox`

Για την αντικαταβολή του voucher

### Αναγνώριση 3rd party πληρωμή αντικαταβολής

Σε κάποιες περιπτώσεις που χρησιμοποιείται μέθοδο πληρωμής (αντικαταβολή) από κάποιο άλλο plugin ή custom. Σε αυτή την περίπτωση το plugin δεν γνωρίζει εαν είναι αντικαταβολή και να προστεθεί αυτόματα στο πεδίο.&#x20;

**alg\_custom\_gateway\_1 =** Είναι το ID  της μεθόδου πληρωμής

```php
add_filter('iben_acs_filter_cashdelivery_payments_order_metabox', 'iben_acs_cash_delivery_add_alg_custom1');
function iben_acs_cash_delivery_add_alg_custom1(){
   return $payments = array('alg_custom_gateway_1');
}

```

### Προσθήκη αρ. παραγγελίας στο πεδιο σχόλια

Σε περίπτωση που θέλετε να εκτυπώνεται ο αρ. παραγγελίας μέσα στα σχόλια του voucher θα πρέπει να χρησιμοποιήσετε την παρακάτω function&#x20;

```php
add_filter('iben_acs_filter_combine_comments_metafield_order', 'iben_acs_override_com_meta', 10, 2);
add_filter('iben_acs_filter_automatic_comments_metafield_order', 'iben_acs_override_com_meta', 10, 2);
add_filter('iben_acs_filter_comments_order_metabox', 'iben_acs_override_com_meta', 10, 2);

function iben_acs_override_com_meta($comment, $order_id){ 
 
    $order = wc_get_order($order_id); 
    if ( !is_a( $order, 'WC_Order' ) ){ return; }
 
    //GET ORDER COMMENTS
    $comments = $order->get_customer_note(); 
    $order_number = $order->get_order_number(); 
    return 'Παραγγελία ID:'.$order_number.' '.$comments;
}
```

### Εμφάνιση προϊόντων στο σχόλια

```php
//works for automatic actions too
add_filter('iben_acs_filter_automatic_comments_metafield_order', 'iben_acs_display_products_in_comments', 10, 2 );
//works for bulk creation too
add_filter('iben_acs_filter_combine_comments_metafield_order', 'iben_acs_display_products_in_comments', 10, 2 );
add_filter('iben_acs_filter_comments_order_metabox', 'iben_acs_display_products_in_comments', 10, 2 );
function iben_acs_display_products_in_comments($comments, $order_id){
	
	$order = wc_get_order($order_id);

	if ( !is_a( $order, 'WC_Order' ) ){ return; }

	$export = '';

	if ($order->get_items()){
		$count = count($order->get_items());
		$index = 0;
		foreach( $order->get_items() as $item_id => $product_item ){
			$index++;
			$product = $product_item->get_product();
			$export .= $product->get_name().' x '.$product_item->get_quantity().($index == $count ? '': ', ');
		}
	}

	// Εμφάνιση προιόντων μόνο
	return $export;
	
	// Εμφάνιση σχόλια πελάτη + προιόντα
	// return $comments.' '.$export;

}
```

### Αλλαγή billing code ανάλογα το βάρος

```php
add_filter('iben_acs_filter_billingcode_order_metabox', 'iben_acs_filter_billing_code', 10, 2);

function iben_acs_filter_billing_code($billingcode, $order_id){

	$order = wc_get_order($order_id);

	if ( !is_a( $order, 'WC_Order' )  ){
		return $billingcode;
	}

    foreach( $order->get_items() as $item_id => $product_item ){

        $total_weight = 0;

        foreach( $order->get_items() as $item_id => $product_item ){
            $quantity = $product_item->get_quantity(); // get quantity
            $product = $product_item->get_product(); // get the WC_Product object
            if( $product ) {
                $product_weight = $product->get_weight(); // get the product weight
                $total_weight += floatval( ( $product_weight ? $product_weight : 0 ) * $quantity );
            }
            
        }
	}

    if ($total_weight < 3){
        return 'billing code 1';
    }else{
        return 'billing code 2';
    }

}
```

### Διαφορετικό ACS λογαριασμό για κάθε admin ID

```php
add_action('admin_init', 'iben_acs_custom_acccounts');

function iben_acs_custom_acccounts(){
	// REQUIRE v1.6.0 and later

	if ( ! class_exists( 'Iben_Woo_Acs_Admin_Woo' ) ) return;
	if ( ! is_admin() ) return;
	if ( !current_user_can( 'edit_shop_orders' ) ) return;

	//display admin bar which account is assigned
	add_filter( 'iben_acs_filter_display_multiaccount_message', '__return_true' );			
	//display in account column in vouchers list
	add_filter( 'iben_acs_filter_vouchers_display_account_column', '__return_true' ); 

	$current_id = get_current_user_id();				
	// ADMIN ID		
	if ($current_id == 1){
		
		add_filter( 'iben_acs_main_company_id', function($default_value ) {
			return 'xxxxx';
		}, 10);

		add_filter( 'iben_acs_main_company_password', function($default_value ) {
			return 'xxxxxx';
		}, 10);
		add_filter( 'iben_acs_main_user_id', function($default_value ) {
			return 'xxxxx';
		}, 10
		);
		add_filter( 'iben_acs_main_user_password', function($default_value ) {
			return '14411';
		}, 10);
		add_filter( 'iben_acs_main_apikey', function($default_value ) {
			return 'e248xxxx3fca40af8ae8bb2cb6c4xxx';
		}, 10);												
		add_filter( 'iben_acs_main_billing_code', function($default_value ) {
			return 'xxxxxx';
		}, 10);												

	// ADMIN ID
	}elseif ($current_id == 2){
		add_filter( 'iben_acs_main_company_id', function($default_value ) {
			return 'demo';
		}, 10);	

		add_filter( 'iben_acs_main_company_password', function($default_value ) {
			return 'demo';
		}, 10);
		add_filter( 'iben_acs_main_user_id', function($default_value ) {
			return 'demo';
		}, 10
		);
		add_filter( 'iben_acs_main_user_password', function($default_value ) {
			return 'demo';
		}, 10);
		add_filter( 'iben_acs_main_apikey', function($default_value ) {
			return 'ff3981a2ac67410e877c1d73e7d83006';
		}, 10);												
		add_filter( 'iben_acs_main_billing_code', function($default_value ) {
			return '2ΑΘ999999';
		}, 10);	
	}

}
```

### Αποστολή email καθε φορά που το δεμά παραδίδεται και έχει αντικαταβολή

```php
// requires iBen ACS v2.5.1 and above
add_action('iben_acs_check_delivery_hook_after_delivered', 'iben_custom_trigger_function_delivered', 10, 2);

function iben_custom_trigger_function_delivered($order_id, $id_record){

	if ( !function_exists( 'iben_acs_get_Vouchers_from_id' ) ) return;

	$data = iben_acs_get_Vouchers_from_id($id_record);

	if (empty($data) && !is_object($data) ) return;

	$voucher = $data->acs_main_voucher;
	$data = maybe_unserialize($data->acs_voucher_info);
	
	//if COD
	if (!isset($data['Cod_Ammount'])) return;

	$cash = str_replace(",",".", $data['Cod_Ammount']);
	$cash = floatval(preg_replace('/\.(?=.*\.)/', '', $cash));

	if ($cash > 0){
		// SEND EMAIL HERE
		$headers = array('Content-Type: text/html; charset=UTF-8');
		$subject = esc_html__( 'Just delivered a COD shipment', 'iben-woo-ups' );
		$body = '<p> ACS voucher: '.$voucher.' ('.$cash.')</p>';

		wp_mail( 'info@ibenetos.com', $subject, $body, $headers );
	}

}
```

### Εμφάνιση σύνολο αντικαταβολών στην λίστα των vouchers

<figure><img src="/files/xwMVAzuxWgxf3uDVj0h4" alt=""><figcaption></figcaption></figure>

```php
add_filter( 'iben_acs_filter_listvouchers_displaycod_all', '__return_true' );
add_filter( 'iben_acs_filter_listvouchers_displaycod_delivered', '__return_true' );
add_filter( 'iben_acs_filter_listvouchers_displaycod_undelivered', '__return_true' );
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://acsdoc.iben.pro/filters/xrisima-filters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
