Skip to content

Commit

Permalink
v4.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo-sg-pacheco committed Jun 24, 2024
1 parent ad2f999 commit 514055c
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 107 deletions.
10 changes: 7 additions & 3 deletions includes/class-alg-wc-oma-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Order Minimum Amount for WooCommerce - Core Class.
*
* @version 4.4.3
* @version 4.4.5
* @since 1.0.0
*
* @author WPFactory
Expand Down Expand Up @@ -596,12 +596,16 @@ function check_limits_for_amount_type_in_result( $result, $amount_type ) {
/**
* checkout_process_notices.
*
* @version 4.3.6
* @version 4.4.5
* @since 2.2.0
*/
function checkout_process_notices() {
if ( 'woocommerce_checkout_process' === get_option( 'alg_wc_oma_block_checkout_hook', 'woocommerce_checkout_process' ) ) {
$this->messages->output_notices( 'checkout', 'wc_add_notice', 'error' );
$this->messages->output_notices( array(
'area' => 'checkout',
'func' => 'wc_add_notice',
'notice_type' => 'error'
) );
}
}

Expand Down
69 changes: 57 additions & 12 deletions includes/class-alg-wc-oma-messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Order Minimum Amount for WooCommerce - Messages.
*
* @version 4.4.1
* @version 4.4.5
* @since 4.0.4
*
* @author WPFactory
Expand Down Expand Up @@ -117,7 +117,7 @@ function get_enabled_message_areas() {
/**
* display_dynamic_message.
*
* @version 4.0.5
* @version 4.4.5
* @since 4.0.4
*
* @param null $args
Expand All @@ -138,7 +138,14 @@ function display_dynamic_message( $args = null ) {
$func = ! $func ? ( isset( $output_notices_params['func'] ) ? $output_notices_params['func'] : $func ) : $func;
$notice_type = isset( $output_notices_params['notice_type'] ) ? $output_notices_params['notice_type'] : $notice_type;
}
$output = $this->output_notices( $area, $func, $notice_type );
$output = $this->output_notices(
array(
'area' => $area,
'func' => $func,
'notice_type' => $notice_type,
'position' => $position,
)
);
if ( false === $func ) {
echo $output;
}
Expand Down Expand Up @@ -301,26 +308,64 @@ function get_notices( $args = null ) {
/**
* output_notices.
*
* @version 4.3.2
* @version 4.4.5
* @since 1.0.0
*
* @param $area 'cart' | 'checkout' | 'product_page'
* @param bool $func
* @param bool $notice_type
* @param $args
*
* @return string
* @return string|void
*/
function output_notices( $area, $func = false, $notice_type = false ) {
$result = $this->get_notices( array(
function output_notices( $args = null ) {
$args = wp_parse_args( $args, array(
'area' => '',
'func' => false,
'notice_type' => false,
'position' => ''
) );
$area = $args['area'];
$func = $args['func'];
$notice_type = $args['notice_type'];
$position = $args['position'];
$result = $this->get_notices( array(
'area' => $area,
'get_only_first_flat_notice' => 'no' === get_option( 'alg_wc_oma_display_multiple_msg', 'yes' ),
) )['flat_notices'];

$templates = array(
'default' => '<div class="alg-wc-oma-msg">{content}</div>',
'in_table' => '<tr><th></th><td><div class="alg-wc-oma-msg">{content}</div></td></tr>'
);

if ( ! $func ) {
return implode( '<br>', $result );
$wrapped_result = array_map( function ( $item ) use ( $templates, $position ) {
$array_from_to = array(
'{content}' => $item,
);
$template = $templates['default'];
if (
in_array( $position, array(
'woocommerce_cart_totals_before_shipping',
'woocommerce_cart_totals_after_shipping',
'woocommerce_cart_totals_before_order_total',
'woocommerce_cart_totals_after_order_total',
'woocommerce_review_order_before_shipping',
'woocommerce_review_order_after_shipping'
) )
) {
$template = $templates['in_table'];
}

return str_replace( array_keys( $array_from_to ), $array_from_to, $template );
}, $result );

return implode( '', $wrapped_result );
} else {
foreach ( $result as $content ) {
call_user_func_array( $func, array( $content, $notice_type ) );
$array_from_to = array(
'{content}' => $content,
);
$final_content = str_replace( array_keys( $array_from_to ), $array_from_to, $templates['default'] );
call_user_func_array( $func, array( $final_content, $notice_type ) );
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion includes/settings/class-alg-wc-oma-settings-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function get_settings() {
array(
//'title' => __( 'Block store api request', 'order-minimum-amount-for-woocommerce' ),
'desc_tip' => __( 'Overwrite store api request at the time of order creation on wrong min/max amount.', 'order-minimum-amount-for-woocommerce' ),
'desc' => __( 'Prevent api user to place order on wrong min/max amount.', 'order-minimum-amount-for-woocommerce' ),
'desc' => __( 'Prevent api user to place order on wrong min/max amount', 'order-minimum-amount-for-woocommerce' ),
'id' => 'alg_wc_oma_block_store_api',
'default' => 'no',
'checkboxgroup' => 'end',
Expand Down
Loading

0 comments on commit 514055c

Please sign in to comment.