Plugin Directory

Changeset 3092786


Ignore:
Timestamp:
05/26/2024 07:22:37 PM (23 months ago)
Author:
theritesites
Message:

1.5.0 - HPOS support

Location:
woo-cost-of-shipping
Files:
19 added
3 edited

Legend:

Unmodified
Added
Removed
  • woo-cost-of-shipping/trunk/README.txt

    r3092545 r3092786  
    33Donate link:       https://www.theritesites.com/plugins/woocommerce-cost-of-shipping 
    44Tags:              cost of shipping, shipping cost, WooCommerce, net profit, shipstation
    5 Requires at least: 4.8.1 
     5Requires at least: 5.2
    66Tested up to:      6.5
    77Requires PHP:      7.0
     
    5959
    6060== Changelog ==
     61
     62= 1.5.0 =
     63- WooCommerce High Performance Order Storage (HPOS) update
    6164
    6265= 1.4.2 =
  • woo-cost-of-shipping/trunk/includes/admin/class-wc-cos-admin-orders.php

    r2911313 r3092786  
    2727 *
    2828 */
     29use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;
    2930
    3031if ( ! defined( 'ABSPATH' ) ) {
     
    177178    /**
    178179     * Callback function for AJAX request to handle the manual shipping cost entry.
    179      * This function will return success on successful update_post_meta for the new shipping cost and method.
     180     * This function will return success on successful $order->update_meta_data for the new shipping cost and method.
    180181     *
    181182     * @since 1.0.0
     
    235236        do_action( 'wc_cos_before_cost_of_shipping_stored', $order_id, $cos, $method );
    236237
     238        // Query wc_order
     239        $order = wc_get_order( $order_id );
     240
    237241        // Store for possible history update before the new store overwrites.
    238         $old_cos = get_post_meta( $order_id, '_wc_cost_of_shipping', true );
    239         $old_method = get_post_meta( $order_id, '_wc_cos_method', true );
     242        $old_cos = $order->get_meta( '_wc_cost_of_shipping', true );
     243        $old_method = $order->get_meta( '_wc_cos_method', true );
    240244
    241245        /**
     
    245249         *   saved by at this point. Might see some functionality wanted later on,
    246250         *   but this will be the simplest way forward to not corrupt data.
     251         *
     252         *  Updated in 1.5.0 for HPOS
    247253         */
    248         $flag = update_post_meta( $order_id, '_wc_cost_of_shipping', ( float ) $cos );
    249         if ( ! $flag ) {
     254        if ( ( float ) $old_cos == ( float ) $cos ) {
    250255            if ( true === $this->plugin->__get( 'debug' ) ) {
    251256                $this->log->add( 'the-rite-sites-profit-plugins', __( '       No need to update Cost of Shipping, values are equivalent.', 'woocommerce-cost-of-shipping' ) );
     
    253258            return false;
    254259        }
    255 
    256         update_post_meta( $order_id, '_wc_cos_method', $method );
     260        $order->update_meta_data( '_wc_cost_of_shipping', ( float ) $cos );
     261
     262        $order->update_meta_data( $order_id, '_wc_cos_method', $method );
    257263
    258264        if ( true === $this->plugin->__get( 'debug' ) ) {
     
    261267
    262268        if ( ! empty( $old_cos ) && ! empty( $old_method ) ) {
    263             $cos_history = maybe_unserialize( get_post_meta( $order_id, '_wc_cos_history' ) );
     269            $dirty_cos_history = $order->get_meta( '_wc_cos_history' );
     270            $cos_history = maybe_unserialize( $dirty_cos_history );
    264271            if ( empty( $cos_history ) ) {
    265272                $cos_history = array();
     
    267274
    268275            $cos_history[] = array( 'method' => $old_method, 'cos' => $old_cos );
    269             update_post_meta( $order_id, '_wc_cos_history', $cos_history );
     276            $order->update_meta_data( '_wc_cos_history', $cos_history );
    270277
    271278            if ( true === $this->plugin->__get( 'debug' ) ) {
     
    274281        }
    275282
     283        $order->save();
    276284        do_action( 'wc_cos_after_cost_of_shipping_stored', $order_id, $cos, $method );
    277285        return true;
     
    342350            }
    343351
    344             $previous_cos_method = get_post_meta( $order_id, '_wc_cos_method', true );
     352            $order = wc_Get_order( $order_id );
     353            $previous_cos_method = $order->get_meta( '_wc_cos_method', true );
    345354            if ( false === $flag && ! ( 'wc_services' === $previous_cos_method ) ) return false;
    346355            if ( true === $this->store_cost_of_shipping( $order_id, $cost_of_shipping, 'wc_services' ) ) {
     
    385394     */
    386395    public function display_wcs_cos_meta_box( $post_id ) {
    387         $order = wc_get_order( $post_id );
     396        $order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object;
     397        // $order = wc_get_order( $post_id );
    388398
    389399        $cos = floatval( $order->get_meta( '_wc_cost_of_shipping' ) );
     
    451461    public function add_wcs_cos_meta_box( $post_type, $post ) {
    452462        if ( $this->should_show_wcs_cos_meta_box() ) {
     463
     464            $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) && wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
     465                    ? wc_get_page_screen_id( 'shop-order' )
     466                    : 'shop_order';
     467
    453468            add_meta_box(
    454469                'wc-cos-services-cost-of-shipping',
    455470                __( 'Import Cost of Shipping', 'woocommerce-cost-of-shipping' ),
    456471                array( $this, 'display_wcs_cos_meta_box' ),
    457                 'shop_order',
     472                $screen,
    458473                'side',
    459474                'default'
     
    584599       
    585600        $ajax_nonce = wp_create_nonce( 'edit-shipping-meta-nonce' );
    586         $cost_of_shipping = floatval( get_post_meta( $post_id, '_wc_cost_of_shipping', true ) );
     601        $order = wc_get_order( $post_id );
     602        $cost_of_shipping = floatval( $order->get_meta( '_wc_cost_of_shipping', true ) );
    587603        $formatted_total = wc_price( $cost_of_shipping );
    588604        ?>
     
    627643    protected function get_formatted_order_shipping_cost( $order_id ) {
    628644
    629         $order_shipping_cost = get_post_meta( $order_id, '_wc_cost_of_shipping', true );
     645        $order = wc_get_order( $order_id );
     646        $order_shipping_cost = $order->get_meta( '_wc_cost_of_shipping', true );
    630647        $formatted_total = wc_price( $order_shipping_cost );
    631648
  • woo-cost-of-shipping/trunk/woocommerce-cost-of-shipping.php

    r3092545 r3092786  
    44 * Plugin URI:  https://www.theritesites.com/plugins/woocommerce-cost-of-shipping
    55 * Description: Allows the association of the cost of shipping to WooCommerce orders
    6  * Version:     1.4.2
     6 * Version:     1.5.0
    77 * Author:      TheRiteSites
    88 * Author URI:  https://www.theritesites.com
     
    1313 * WC tested up to: 8.9
    1414 * WC requires at least: 3.0
     15 * Requires at least: 5.2
    1516 *
    1617 * @link    https://www.theritesites.com/plugins/woocommerce-cost-of-shipping
    1718 *
    1819 * @package WC_COS
    19  * @version 1.4.2
     20 * @version 1.5.0
    2021 */
    2122
     
    2526 * developed by TheRiteSites and found at https://www.theritesites.com/plugins/woocommerce-net-profit
    2627 *
    27  * Copyright (c) 2020,2022 TheRiteSites (email : contact@theritesites.com)
     28 * Copyright (c) 2020,2024 TheRiteSites (email : contact@theritesites.com)
    2829 *
    2930 * This program is free software; you can redistribute it and/or modify
     
    6162     * @since  1.0.0
    6263     */
    63     const VERSION = '1.4.2';
     64    const VERSION = '1.5.0';
    6465
    6566    /**
     
    347348register_activation_hook( __FILE__, array( wc_cos(), '_activate' ) );
    348349register_deactivation_hook( __FILE__, array( wc_cos(), '_deactivate' ) );
     350
     351add_action( 'before_woocommerce_init', function() {
     352    if ( class_exists( \Automattic\WooCommerce\Utilities\FeaturesUtil::class ) ) {
     353        \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true );
     354    }
     355} );
Note: See TracChangeset for help on using the changeset viewer.