• Resolved quiron

    (@quiron)


    Hello!

    first of all thanks for your work in this plugin.

    I realized that actually the plugin code is not following the WooCommerce recomendations regarding CRUD operations: https://docs.woocommerce.com/document/developing-using-woocommerce-crud-objects/

    To fix it regarding Order objects it can be done by:

    
    --- a/woocommerce-product-price-based-on-countries/includes/class-wcpbc-frontend-pricing.php
    +++ b/woocommerce-product-price-based-on-countries/includes/class-wcpbc-frontend-pricing.php
    @@ -491,7 +491,8 @@ class WCPBC_Frontend_Pricing {
             * @param array $data Order metadata.
             */
            public static function update_order_meta( $order_id, $data ) {
    -               update_post_meta( $order_id, '_wcpbc_base_exchange_rate', wcpbc_the_zone()->get_base_currency_amount( 1 ) );
    -               update_post_meta( $order_id, '_wcpbc_pricing_zone', wcpbc_the_zone()->get_data() );
    +               $order = wc_get_order( $order_id );
    +               $order->update_meta_data( '_wcpbc_base_exchange_rate', wcpbc_the_zone()->get_base_currency_amount( 1 ) );
    +               $order->update_meta_data( '_wcpbc_pricing_zone', wcpbc_the_zone()->get_data() );
            }
     }
    diff --git a/woocommerce-product-price-based-on-countries/includes/class-wcpbc-pricing-zones.php b/woocommerce-product-price-based-on-countries/includes/class-wcpbc-pricing-zones.php
    index fe7aeeb7..456508c7 100644
    --- a/woocommerce-product-price-based-on-countries/includes/class-wcpbc-pricing-zones.php
    +++ b/woocommerce-product-price-based-on-countries/includes/class-wcpbc-pricing-zones.php
    @@ -233,14 +233,15 @@ class WCPBC_Pricing_Zones {
                    }
     
                    if ( $order_id ) {
    -                       $data = get_post_meta( $order_id, '_wcpbc_pricing_zone', true );
    +                       $order = wc_get_order( $order_id );
    +                       $data = $order->get_meta( '_wcpbc_pricing_zone', true );
     
                            if ( $data ) {
                                    $zone = self::get_zone( $data );
                            } else {
                                    // Find zone by order country.
                                    $based_on = get_option( 'wc_price_based_country_based_on', 'billing' );
    -                               $country  = get_post_meta( $order_id, '_' . $based_on . '_country', true );
    +                               $country  = $order->get_meta( '_' . $based_on . '_country', true );
                                    $zone     = self::get_zone_by_country( $country );
                            }
                    }
    
    

    Would be awesome to see it introduced in the next release. If there is another better way to contribute code improvements I will be happy to use it.

    Thanks so much.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Oscar Gare

    (@oscargare)

    Hi,
    Thanks for your feedback.

    Currently, PBoC keeps compatibility with WooCommerce 2.6. The changes you propose breaks the backward compatibility.

    We have planned to update the compatibility to WooCommerce 3.0+ in the next major release.

    Thank you again.

    Thread Starter quiron

    (@quiron)

    Hi,

    Thanks for your fast and helpful response. When is it planned to publish the next major release? If it takes long maybe we can introduce it with a version check to don’t break backward compatibility. Will this be an option?

    thanks so much.

    • This reply was modified 5 years, 2 months ago by quiron.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Plugin not following WooCommerce developer recommendations for CRUD operations’ is closed to new replies.