price calculation now works whatever acf return is set
This commit is contained in:
@@ -10,6 +10,31 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* return value of an acf field, no matter if the field is set up to return label or value
|
||||
*
|
||||
*/
|
||||
function get_acf_value_CIPF($field_name, $acf_id) {
|
||||
$field_object = get_field_object($field_name, $acf_id);
|
||||
$return_format = $field_object['return_format'];
|
||||
$field = get_field($field_name, $acf_id);
|
||||
|
||||
$value = null;
|
||||
if ($return_format === 'array') {
|
||||
$value = $field['value'];
|
||||
}
|
||||
else if ($return_format === 'value') {
|
||||
$value = $field;
|
||||
}
|
||||
else if ($return_format === 'label') {
|
||||
$choices = $field_object['choices'];
|
||||
$value = array_search($field, $choices);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* can pay in certain conditions
|
||||
@@ -44,81 +69,14 @@ function check_can_pay_CIPF() {
|
||||
* in case it was changed from admin pannel
|
||||
*
|
||||
*/
|
||||
$tarif_object = get_field_object($acf_card_price_choice['_name'], $acf_id);
|
||||
error_log("tarif_object");
|
||||
error_log(json_encode($tarif_object));
|
||||
/*
|
||||
{
|
||||
"ID":34541,
|
||||
"key":"field_65d24447cc89f",
|
||||
"label":"Tarif",
|
||||
"name":"tarif",
|
||||
"aria-label":"",
|
||||
"prefix":"acf",
|
||||
"type":"radio",
|
||||
"value":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac",
|
||||
"menu_order":3,
|
||||
"instructions":"",
|
||||
"required":0,
|
||||
"id":"",
|
||||
"class":"",
|
||||
"conditional_logic":0,
|
||||
"parent":34538,
|
||||
"wrapper":{
|
||||
"width":"",
|
||||
"class":"",
|
||||
"id":""
|
||||
},
|
||||
"choices":{
|
||||
"10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac",
|
||||
"15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac"
|
||||
},
|
||||
"default_value":"",
|
||||
"return_format":"label",
|
||||
"allow_null":0,
|
||||
"other_choice":0,
|
||||
"layout":"vertical",
|
||||
"save_other_choice":0,
|
||||
"_name":"tarif",
|
||||
"_valid":1
|
||||
}
|
||||
{
|
||||
"ID":34541,
|
||||
"key":"field_65d24447cc89f",
|
||||
"label":"Tarif",
|
||||
"name":"tarif",
|
||||
"aria-label":"",
|
||||
"prefix":"acf",
|
||||
"type":"radio",
|
||||
"value":"15",
|
||||
"menu_order":3,
|
||||
"instructions":"",
|
||||
"required":0,"id":"",
|
||||
"class":"",
|
||||
"conditional_logic":0,
|
||||
"parent":34538,
|
||||
"wrapper":{"width":"","class":"","id":""},
|
||||
"choices":{
|
||||
"10":"Mon association adh\u00e8re \u00e0 la FIPF, je peux commander la carte \u00e0 10 \u20ac",
|
||||
"15":"Je suis hors r\u00e9seau FIPF et je souhaite commander la carte \u00e0 15 \u20ac"
|
||||
},
|
||||
"default_value":"",
|
||||
"return_format":"value",
|
||||
"allow_null":0,
|
||||
"other_choice":0,
|
||||
"layout":"vertical",
|
||||
"save_other_choice":0,
|
||||
"_name":"tarif",
|
||||
"_valid":1
|
||||
}
|
||||
*/
|
||||
// $tarif_value = ;
|
||||
// $tarif = (int)$tarif_value;
|
||||
$livraison_object = get_field_object($acf_card_price_delivery['_name'], $acf_id);
|
||||
// $livraison_value = ;
|
||||
// $livraison = (int)$livraison_value;
|
||||
// $price = $tarif + $livraison;
|
||||
$price = 3;
|
||||
$tarif = get_acf_value_CIPF($acf_card_price_choice['_name'], $acf_id);
|
||||
$livraison = get_acf_value_CIPF($acf_card_price_delivery['_name'], $acf_id);
|
||||
if ($tarif !== null && $livraison !== null) {
|
||||
$price = $tarif + $livraison;
|
||||
}
|
||||
else {
|
||||
$price = 0;
|
||||
}
|
||||
update_field($acf_card_price_total['_name'], $price, $acf_id);
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user