Show countries for delivery process forms. Refactor countries.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Countries {
|
||||
|
||||
public static function init() {
|
||||
|
||||
// Add countries fields to countries list
|
||||
add_filter( 'manage_edit-product_country_columns', array( __CLASS__, 'update_list_headers' ) );
|
||||
add_filter( 'manage_product_country_custom_column', array( __CLASS__, 'update_list_column_content' ), 10, 3 );
|
||||
|
||||
// Validate country settings
|
||||
add_filter('acf/load_field/name=_wiaas_country_code', array(__CLASS__, 'populate_country_codes'));
|
||||
add_filter('acf/load_field/name=_wiaas_country_currency', array(__CLASS__, 'populate_country_currencies'));
|
||||
}
|
||||
|
||||
public static function update_list_headers($columns) {
|
||||
$columns['wiaas_code'] = __( 'Code', 'wiaas' );
|
||||
|
||||
$columns['wiaas_vat'] = __('VAT', 'wiaas');
|
||||
|
||||
$columns['wiaas_currency'] = __('Currency', 'wiaas');
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public static function update_list_column_content($columns, $column, $id) {
|
||||
|
||||
if ($column === 'wiaas_code') {
|
||||
|
||||
$code = get_term_meta($id, '_wiaas_country_code', true);
|
||||
$columns .= '<span>'. $code . '</span>';
|
||||
}
|
||||
|
||||
if ($column === 'wiaas_vat') {
|
||||
|
||||
$vat = get_term_meta($id, '_wiaas_country_vat', true);
|
||||
$columns .= '<span>'. $vat . '</span>';
|
||||
}
|
||||
|
||||
if ($column === 'wiaas_currency') {
|
||||
|
||||
$currency = get_term_meta($id, '_wiaas_country_currency', true);
|
||||
$columns .= '<span>'. $currency . '</span>';
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public static function populate_country_codes($field) {
|
||||
$countries_list = Wiaas_Countries::get_country_choices();
|
||||
|
||||
$countries_choices = array();
|
||||
foreach ($countries_list as $code => $name) {
|
||||
|
||||
$countries_choices[$code] = $code . ' - ' . $name;
|
||||
}
|
||||
|
||||
$field['choices'] = $countries_choices;
|
||||
|
||||
return $field;
|
||||
}
|
||||
|
||||
public static function populate_country_currencies($field) {
|
||||
|
||||
$field['choices'] = Wiaas_Countries::get_currency_choices();
|
||||
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Countries::init();
|
||||
@@ -7,6 +7,7 @@ class Wiaas_Admin_Delivery_Process {
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/wiaas-admin-delivery-process-ajax.php';
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-flow.php';
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-order.php';
|
||||
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-list.php';
|
||||
|
||||
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
class Wiaas_Admin_Delivery_Process_List {
|
||||
|
||||
public static function init() {
|
||||
|
||||
add_filter('gform_form_list_columns', array( __CLASS__, 'filter_gform_form_list_columns' ));
|
||||
|
||||
add_filter('gform_form_list_forms', array( __CLASS__, 'filter_gform_form_list_forms' ), 10, 6);
|
||||
|
||||
add_filter('gform_form_actions', array( __CLASS__, 'filter_gform_form_actions' ), 10, 2);
|
||||
|
||||
add_action('gform_form_list_column_wiaas_country', array( __CLASS__, 'render_gform_form_list_wiaas_country_column' ));
|
||||
|
||||
add_action('gform_form_list_column_wiaas_actions', array( __CLASS__, 'render_gform_form_list_wiaas_actions_column' ));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide not needed columns for delivery process list
|
||||
* Add country column
|
||||
* Add actions column
|
||||
*
|
||||
* @param array $columns
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filter_gform_form_list_columns($columns) {
|
||||
|
||||
unset($columns['entry_count']);
|
||||
unset($columns['conversion']);
|
||||
unset($columns['view_count']);
|
||||
|
||||
$columns['wiaas_country'] = esc_html__( 'Country', 'wiaas' );
|
||||
$columns['wiaas_actions'] = esc_html__( 'Actions', 'wiaas' );
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter delivery process forms list with search query by title and country
|
||||
* @param array $forms
|
||||
* @param string $search_query
|
||||
* @param bool $active
|
||||
* @param string $sort_column
|
||||
* @param string $sort_direction
|
||||
* @param bool $trash
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function filter_gform_form_list_forms($forms, $search_query, $active, $sort_column, $sort_direction, $trash) {
|
||||
|
||||
$forms = GFFormsModel::get_forms( $active, $sort_column, $sort_direction, $trash );
|
||||
|
||||
if ( ! rgblank( $search_query ) ) {
|
||||
|
||||
$filtered_forms = array();
|
||||
$search_query = strtolower($search_query);
|
||||
|
||||
// filter forms
|
||||
foreach ($forms as $form) {
|
||||
|
||||
$form_details = GFAPI::get_form( $form->id );
|
||||
|
||||
$title = strtolower($form_details['title']);
|
||||
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
$country_code = ! empty($delivery_settings) ? $delivery_settings['delivery_country'] : '';
|
||||
$country_name = Wiaas_Countries::get_available_country_name_by_code($country_code);
|
||||
$country_name = strtolower($country_name);
|
||||
|
||||
if (strpos($title, $search_query) !== false || strpos($country_code, $search_query) !== false ||
|
||||
strpos($country_name, $search_query) !== false) {
|
||||
$filtered_forms[] = $form;
|
||||
}
|
||||
}
|
||||
|
||||
return $filtered_forms;
|
||||
}
|
||||
|
||||
return $forms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove unused actions and add workflow action for delivery forms list
|
||||
*
|
||||
* @param array $actions
|
||||
* @param int $form_id
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function filter_gform_form_actions($actions, $form_id) {
|
||||
|
||||
$form_details = GFAPI::get_form($form_id);
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
|
||||
if (empty($delivery_settings)) {
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
$type = $delivery_settings['delivery_form_type'];
|
||||
|
||||
$is_action = $type === 'action';
|
||||
|
||||
if (!$is_action) {
|
||||
|
||||
unset($actions['entries']);
|
||||
}
|
||||
|
||||
unset($actions['entries']);
|
||||
unset($actions['preview']);
|
||||
unset($actions['edit']);
|
||||
|
||||
$actions['wiaas_workflow'] = array(
|
||||
'label' => __( 'Workflow', 'wiaas' ),
|
||||
'short_label' => esc_html__( 'Workflow', 'wiaas' ),
|
||||
'title' => __( 'Edit workflow', 'wiaas' ),
|
||||
'url' => '?page=gf_edit_forms&view=settings&id=' . $form_id . '&subview=gravityflow',
|
||||
'priority' => 1000,
|
||||
);
|
||||
|
||||
return $actions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render country column for delivery process forms list
|
||||
*
|
||||
* @param mixed $form
|
||||
*/
|
||||
public static function render_gform_form_list_wiaas_country_column($form) {
|
||||
|
||||
$form_details = GFAPI::get_form($form->id);
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
|
||||
$country_code = ! empty($delivery_settings) ? $delivery_settings['delivery_country'] : '';
|
||||
|
||||
$country_name = Wiaas_Countries::get_available_country_name_by_code($country_code);
|
||||
|
||||
echo '<strong>' . esc_html_e($country_name) . '</strong>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render actions column for delivery process forms list
|
||||
* @param mixed $form
|
||||
*/
|
||||
public static function render_gform_form_list_wiaas_actions_column($form) {
|
||||
|
||||
$form_details = GFAPI::get_form($form->id);
|
||||
$delivery_settings = rgar($form_details, 'wiaas_delivery_process');
|
||||
|
||||
$form_type = ! empty($delivery_settings) ? $delivery_settings['delivery_form_type'] : '';
|
||||
|
||||
?>
|
||||
<a href="<?php echo '?page=gf_edit_forms&view=settings&id=' . $form->id . '&subview=gravityflow' ?>">Workflow</a>
|
||||
<?php
|
||||
|
||||
if ($form_type !== 'action') {
|
||||
|
||||
?>
|
||||
<span style="margin: 0 10px; opacity: 0.3;"> | </span>
|
||||
<a href="<?php echo '?page=gf_edit_forms&view=settings&id=' . $form->id . '&subview=wiaas_delivery_process' ?>">Change Country</a>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Wiaas_Admin_Delivery_Process_List::init();
|
||||
@@ -58,11 +58,9 @@ class Wiaas_Admin_Delivery_Process_Order {
|
||||
|
||||
if ( empty($process_entry) ) {
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$country_code = Wiaas_Order::get_order_country_code($order_id);
|
||||
|
||||
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country(
|
||||
Wiaas_Countries::get_country_code_by_currency($order->get_currency())
|
||||
);
|
||||
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country($country_code);
|
||||
|
||||
?>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user