• Resolved JapeNZ

    (@japenz)


    It seems this no longer works.

    Not sure if it’s due to a Woo update, but it stopped working for me.

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter JapeNZ

    (@japenz)

    So after a bit of testing it seems the plugin doesn’t work with High-Performance Order Storage (HPOS).

    Any chance of an update to make it HPOS compatible?

    Thanks for your help!

    Thread Starter JapeNZ

    (@japenz)

    So I think I’ve been able to get it to work with HPOS by changing the code at the start from:

    /**
    * Load JavaScript for our administration
    */

    add_action('admin_enqueue_scripts', function() {
    global $pagenow;

    if(is_admin()
    && in_array($pagenow, ['post.php', 'post-new.php'])
    && ($_GET['post_type'] ?: 'shop_order') === 'shop_order')
    {
    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script( 'shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    )
    );
    }
    });

    to:

    /**
    * Load JavaScript for our administration
    */

    add_action('admin_enqueue_scripts', function() {
    global $pagenow, $post;

    if(is_admin()
    && in_array($pagenow, ['post.php', 'post-new.php'])
    && ( $post && get_post_type( $post->ID ) === 'shop_order' ))
    {
    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script( 'shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    )
    );
    }
    });

    So far it seems to have worked, but if you can see anything that might break stuff please let me know! ??

    • This reply was modified 5 months, 2 weeks ago by JapeNZ.

    I came to this thread through this request: https://www.ads-software.com/support/topic/shipping-in-admin-manual-orders/

    After testing the plugin unsuccessfully, and trying the patch above in this thread, it didn’t work for any method, simply the javascript file doesn’t loaded in the admin side

    I have made this modification, and it works for both WC flat rate and Fish and Ships (it should work for any shipping method):

    /**
    * Load JavaScript for our administration
    */
    add_action('admin_enqueue_scripts', function() {
    global $pagenow;

    if(is_admin()
    /* Obsolete code:
    && in_array($pagenow, ['post.php', 'post-new.php'])
    && ($_GET['post_type'] ?: 'shop_order') === 'shop_order')

    Patched code: */
    && $pagenow == 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] == 'wc-orders'
    // that's all folks ;)
    {
    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script( 'shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    )
    );
    }
    });

    Please note that this modification is subject to improvement and that you make it at your own risk.

    Please, post here any feedback on this modification, as it is about this plugin and not about Fish and Ships specifically ??

    Kind regards,
    Carles Martin
    https://www.ads-software.com/plugins/fish-and-ships/

    I just came here to say I’d found a solution as had hit the same issue… and then saw your post. Nearly identical solution to yours. Setup to work for both HPOS and old CPT orders

    /**
    * Load JavaScript for our administration
    */
    add_action('admin_enqueue_scripts', function() {
    global $pagenow;

    if (is_admin() && (
    in_array($pagenow, ['post.php', 'post-new.php']) &&
    ($_GET['post_type'] ?: 'shop_order') === 'shop_order' ||
    ($pagenow === 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'wc-orders' && isset($_GET['action']) && $_GET['action'] === 'new')
    )) {
    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script('shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    )
    );
    }
    });
    • This reply was modified 5 months, 2 weeks ago by tictok.

    Hi, @tictok, surely is better to keep the post.php / post-new.php for backward compatibility, but looking at your code (surely better than mine for that) I think you must cover also action=edit.

    To check it, please, save the order created and reload the page after that. Still working, or fail the JS loading?

    hey @wpcentrics, ahhh, yeah, you’re right, nice spot!

    Shows why testing different scenarios is important. Thanks.

    updated to include order edit scenario. Works for me:

    /**
    * Load JavaScript for our administration
    * UPDATED TO WORK WITH HPOS
    */
    add_action('admin_enqueue_scripts', function() {
    global $pagenow;

    if (is_admin() && (
    (in_array($pagenow, ['post.php', 'post-new.php']) &&
    ($_GET['post_type'] ?? 'shop_order') === 'shop_order') ||
    ($pagenow === 'admin.php' && isset($_GET['page']) && $_GET['page'] === 'wc-orders' && isset($_GET['action']) && in_array($_GET['action'], ['new', 'edit']))
    )) {
    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script('shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    )
    );
    }
    });


    p.s. I didn’t see your solution when I posted… only a minute apart! Not come across Fish and Ships before, I’ll check it out. I’m using this with Tree Table Rate Shipping (TRS).

    EDIT:// Kind of wrong thread, but just seen your video. Fish and Ships looks good. Think I’ll give it ago. Assuming I can create parent rules based on postcode? Thanks

    Thread Starter JapeNZ

    (@japenz)

    Hi guys ( @wpcentrics , @tictok )
    Thank you both so much for taking a look at this, and posting your updates within a minute of each other… amazing! ??

    As I’m in the process of switching over to Fish and Ships I’ll use the code from @wpcentrics.
    The code posted was missing the bracket after ‘wc-orders’ and caused a critical error, but works perfectly with the bracket in place.

    Updated code for anyone who might need it:

    /**
    * Load JavaScript for our administration
    */
    add_action('admin_enqueue_scripts', function() {
    global $pagenow;

    if(is_admin()
    /* Obsolete code:
    && in_array($pagenow, ['post.php', 'post-new.php'])
    && ($_GET['post_type'] ?: 'shop_order') === 'shop_order')

    Patched code: */
    && $pagenow == 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] == 'wc-orders')
    // that's all folks ;)
    {
    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script( 'shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    )
    );
    }
    });
    • This reply was modified 5 months, 1 week ago by JapeNZ.
    Thread Starter JapeNZ

    (@japenz)

    Interestingly while the code works for Fish and Ships, it didn’t work for Woocommerce Table Rate Shipping that I still need to use on the live site while swapping over to Fish and Ships.

    I’ve managed to get it working for both by sort of merging all three of our attempts hah!

    Here’s the latest code in case anyone has the same trouble:

    /* Load JavaScript for our administration */

    add_action('admin_enqueue_scripts', function() {

    global $pagenow, $post;

    if (is_admin()

    && (( in_array($pagenow, ['post.php', 'post-new.php'])
    && ( $post && get_post_type( $post->ID ) === 'shop_order' ))
    || ( $pagenow == 'admin.php' && isset( $_GET['page'] ) && $_GET['page'] == 'wc-orders' )
    )
    ){

    wp_enqueue_script('shipping-calc_js', plugins_url('js/admin-shipping-calc.js', __FILE__));
    wp_localize_script( 'shipping-calc_js', 'shipping_calc', array(
    'url' => admin_url('admin-ajax.php'),
    'nonce' => wp_create_nonce('admin_shipping_calculate')
    ));
    }

    });

    @tictok : glad 2 help! ??

    @japenz : This patch only load the plugin JavaScript file again, there is no doubt that without this JS file the plugin will does nothing. But it does not guarantee that there are no other problems in the way shipping costs are calculated in some methods… or in a future again. You should lookin for some alternative which is maintained.

    Kind regards,
    Carles Martin
    wp-centrics

    Thread Starter JapeNZ

    (@japenz)

    Hi @wpcentrics,

    You’re absolutely right, I’ve been looking for a really long time for an alternative that is maintained but haven’t been able to find anything… hence trying to adapt this one.

    If you hear of any alternatives please let me know, and thank you for your help again ??

    Kind regards,
    JP

Viewing 10 replies - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.