Skip to content

Commit

Permalink
Merge pull request #63 from luizbills/layout-flex
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbills authored May 28, 2023
2 parents 612db25 + 2d40aed commit 5376d15
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 21 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

All notable changes to this project will be documented in this file.

## 2.0.0 - 2023-03-08
## 2.1.0 - 2023-05-28

[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/2.0.0...2.1.0)

- New filter hook: `wc_shipping_simulator_wrapper_css_class`.
- Tweak: improve inline inputs form layout.
- Tweak: improve general CSS.
- Fix: hide free shipping if requires coupon.

## 2.0.0 - 2023-05-15

[Source code changes](https://github.com/luizbills/shipping-simulator-for-woocommerce/compare/1.9.0...2.0.0)

Expand Down
27 changes: 23 additions & 4 deletions assets/css/form.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
#wc-shipping-sim {
padding: 1.5em 0;
border-top: 0.1em solid #e0e0e0;
font-size: 16px;
}
#wc-shipping-sim-form-fields {

.inline-inputs #wc-shipping-sim-form-fields {
display: flex;
align-items: stretch;
}
#wc-shipping-sim-form-fields .input-postcode {
.inline-inputs #wc-shipping-sim-form-fields .input-postcode {
width: 100%;
max-width: 200px;
margin-right: 0.5rem;
max-width: 12em;
margin-right: 0.5em;
padding: 0.75em;
}

.inline-inputs #wc-shipping-sim-form-fields .button.submit,
.inline-inputs #wc-shipping-sim-form-fields .input-postcode {
height: 3em;
}

#wc-shipping-sim-form-fields .button.submit,
#wc-shipping-sim-form-fields .input-postcode {
border-radius: 3px;
font-size: 1em;
}

#wc-shipping-sim-results,
#wc-shipping-sim-debug-box {
margin-top: 1em;
}
#wc-shipping-sim-form-fields .input-postcode:disabled {
background-color: #dee2e6;
Expand Down
11 changes: 10 additions & 1 deletion classes/Admin/inc/settings_fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@
'default' => __( 'Unfortunately at this moment this product cannot be delivered to the specified region.', 'wc-shipping-simulator' ),
'css' => 'height: 6rem;',
],
[
'id' => $prefix . 'settings',
'type' => 'sectionend',
],
[
'id' => $prefix . 'settings_debug',
'type' => 'title',
'name' => esc_html__( 'Debug', 'wc-shipping-simulator' ),
],
[
'id' => $prefix . 'debug_mode',
'type' => 'checkbox',
'name' => esc_html__( 'Debug mode', 'wc-shipping-simulator' ),
'desc' => esc_html__( 'Enable', 'wc-shipping-simulator' ),
'desc_tip' => __( 'Enable debug mode to log your shipping simulations and display helpful tips.', 'wc-shipping-simulator' ),
'desc_tip' => __( 'Enable debug mode to log your shipping simulations and display helpful informations in product page.', 'wc-shipping-simulator' ),
'default' => 'no'
],
[
Expand Down
14 changes: 14 additions & 0 deletions classes/Integration/Brazil.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,23 @@ public function add_hooks () {
add_action( 'wc_shipping_simulator_validate_request_data', [ $this, 'validate_request_data' ] );

add_filter( 'wc_shipping_simulator_request_update_package', [ $this, 'update_package' ], 10, 2 );

add_filter( 'wc_shipping_simulator_wrapper_css_class', [ $this, 'wrapper_css_class' ] );

add_filter( 'wc_shipping_simulator_form_input_type', [ $this, 'form_input_type' ] );
}
}

public function form_input_type ( $type ) {
$type = 'tel';
return $type;
}

public function wrapper_css_class ( $css_class ) {
$css_class[] = 'inline-inputs';
return $css_class;
}

public function prepare_request_data ( $data, $posted ) {
$data['country'] = h::get( $posted['country'], 'BR' );
return $data;
Expand Down
11 changes: 7 additions & 4 deletions classes/Integration/Free_Shipping.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ public function add_hooks () {

public function shipping_package_rates ( $rates, $package ) {
if ( count( $rates ) > 0 ) {
$found = false;
$found = 0;
foreach ( $rates as $key => $rate ) {
if ( 'free_shipping' === $rate->get_method_id() ) {
$found++;
$method = new WC_Shipping_Free_Shipping( $rate->get_instance_id() );
if ( in_array( $method->requires, [ 'min_amount', 'either' ] ) && $package['contents_cost'] < $method->min_amount ) {
$requires_min_amount = in_array( $method->requires, [ 'min_amount', 'either' ] );
$requires_coupon = in_array( $method->requires, [ 'coupon', 'both' ] );
if ( $requires_coupon || $requires_min_amount && $package['contents_cost'] < $method->min_amount ) {
unset( $rates[ $key ] );
$found = true;
$found--;
}
}
}
$package['HAS_FREE_SHIPPING'] = $found;
$package['HAS_FREE_SHIPPING'] = $found >= 1;
}
return $rates;
}
Expand Down
6 changes: 5 additions & 1 deletion classes/Shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public function render_shortcode ( $atts ) {
'ajax_action' => Request::get_ajax_action(),
'product_type' => $product->get_type(),
'product_id' => $product->get_id(),
'css_class' => implode( ' ', apply_filters(
'wc_shipping_simulator_wrapper_css_class',
[]
) ),

// customizable template variables
'input_placeholder' => apply_filters(
Expand All @@ -52,7 +56,7 @@ public function render_shortcode ( $atts ) {
),
'input_type' => apply_filters(
'wc_shipping_simulator_form_input_type',
'tel'
'text'
),
'input_value' => apply_filters(
'wc_shipping_simulator_form_input_value',
Expand Down
15 changes: 8 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion main.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Shipping Simulator for WooCommerce
Plugin URI: https://github.com/luizbills/shipping-simulator-for-woocommerce
Description: Allows your customers to calculate the shipping rates on the product page
Version: 2.0.0
Version: 2.1.0
Requires at least: 4.9
Requires PHP: 7.4
Author: Luiz Bills
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Contributors: luizbills
Donate link: https://luizpb.com/donate/
Tags: woocommerce, shipping simulator, simulador de frete, brazil, brasil, calculadora de frete, shipping calculator, product
Stable tag: 2.0.0
Stable tag: 2.1.0
Requires at least: 4.9
Requires PHP: 7.4
Tested up to: 6.2
Expand Down
2 changes: 1 addition & 1 deletion templates/shipping-simulator-form.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php extract( $args ); ?>
<section id="wc-shipping-sim">
<section id="wc-shipping-sim" class="<?php echo esc_attr( $css_class ) ?>">
<?php do_action( 'wc_shipping_simulator_wrapper_start' ) ?>

<form method="POST" enctype="application/x-www-form-urlencoded" id="wc-shipping-sim-form" data-ajax-action="<?php echo esc_attr( $ajax_action ) ?>" data-product-id="<?php echo esc_attr( $product_id ); ?>" data-product-type="<?php echo esc_attr( $product_type ); ?>">
Expand Down

0 comments on commit 5376d15

Please sign in to comment.