Forum Replies Created

Viewing 15 replies - 1 through 15 (of 113 total)
  • Thread Starter tictok

    (@tictok)

    HiΒ Aslam, thanks fro your reply

    I addedΒ the debug logging and checked the results. The SQL JOIN is being generated correctly – I canΒ seeΒ wp_rwpp_product_orderΒ joined withΒ category_id = 21Β on lines 2-4 of the log below.

    However,Β WooCommerceΒ is overridingΒ the ORDER BY clause. The final query shows:

    ORDER BY 
    CASE istockstatus.meta_value
    WHEN 'outofstock' THEN 1
    ELSE 0
    END ASC,
    wc_product_meta_lookup.average_rating DESC,
    wc_product_meta_lookup.rating_count DESC,
    wc_product_meta_lookup.product_id DESC

    So it’s usingΒ WooCommerce’s default sorting (stock status β†’ rating β†’ product ID) instead ofΒ rwpp_order.sort_order. TheΒ orderby_product_order()Β filter runs, but WooCommerceΒ replaces the ORDERΒ BY with itsΒ own logic.

    ThisΒ suggests theΒ posts_orderbyΒ filter approach doesn’t work with WooCommerce’s query handling. TheΒ meta_queryΒ approach withΒ orderby => ‘meta_value_num’Β works because WooCommerce respectsΒ native WP_Query parameters.

    Here’s the relevant logΒ excerpt showing both queries:

    [RWPP INFO] Complete SQL Query: SELECT SQL_CALC_FOUND_ROWS  wp_posts.*
    FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id)
    LEFT JOIN wp_rwpp_product_order AS rwpp_order
    ON wp_posts.ID = rwpp_order.product_id
    AND rwpp_order.category_id = 21
    ...
    ORDER BY
    CASE istockstatus.meta_value
    WHEN 'outofstock' THEN 1
    ELSE 0
    END ASC, wc_product_meta_lookup.average_rating DESC,
    wc_product_meta_lookup.rating_count DESC,
    wc_product_meta_lookup.product_id DESC

    Hope that helps narrow it down.

    Thanks!

    Thread Starter tictok

    (@tictok)

    Hi – I’ve been looking into this further and can see why you’ve made the changes you did and also why I think it’s not working for me (and possibly others).

    I could see the custom DB table was created, and product IDs, category IDs and sorting update correctly in the table, so needed to look at how the data is being used on the front end.

    Your 5.0.x refactor changed frontend sorting from meta_query (v4.3.3) to custom SQL JOINs against the new wp_rwpp_product_order table. This doesn’t play well with WooCommerce’s query handling because:
    – WooCommerce has its own ordering logic that can override raw SQL modifications
    – The posts_orderby filter gets overridden by WooCommerce’s sorting mechanisms
    – The custom JOIN approach doesn’t integrate with WP_Query’s native ordering system

    I think the custom table is much better than storing everything in wp_posts and wp_postmeta – it’s just I think the frontend WP_Query integration that works better with native meta_query.

    I got 5.0.x working on my woo store. Since the plugin already maintains legacy postmeta (rwpp_sortorder_{term_id}), I updated the sort_products_by_category() method to use the original meta_query approach you used in 4.3.3:

    $meta_key = 'rwpp_sortorder_' . $term_id;
    $query->set('meta_query', [
    'relation' => 'OR',
    ['key' => $meta_key, 'compare' => 'EXISTS'],
    ['key' => $meta_key, 'compare' => 'NOT EXISTS'],
    ]);
    $query->set('orderby', 'meta_value_num menu_order title');
    $query->set('order', 'ASC');

    The same fix/change would likely be needed for modify_product_category_shortcode_query().
    Also noticed that the activation hook in Plugin.php should probably be registered in the main plugin file using ‘__FILE__’ instead of RWPP_BASENAME to ensure the custom table always gets created.

    Hope that’s maybe of some use
    Thanks

    Thread Starter tictok

    (@tictok)

    Hey, thanks @spiderwares, thats great new. I’ll give it ago. Feedback/rating given πŸ˜‰

    Thread Starter tictok

    (@tictok)

    Hey, thanks @spiderwares

    No need to apologise at all!
    No frustration on my part, and I’m really grateful for the updates you’re making…. above and beyond!

    Really no hurry from my point of view, I have a good workaround for now πŸ™‚

    Best regards

    Thread Starter tictok

    (@tictok)

    Hey many thanks for the update @spiderwares
    It’s great that you’ve added it to the beta / future woo block editor!
    Really sorry to say though, that’s not the block editor I meant.

    For years, myself and others have been enabling the block editor on woocommerce product edit pages. Some themes have a built in way to enable or toggle it, or it can be done in child theme with a snippet similar to this:

    add_filter('use_block_editor_for_post_type', function ($is_enabled, $post_type) {
    if ($post_type === 'product') {
    return true; // Enable the block editor for WooCommerce products
    }
    return $is_enabled;
    }, 10, 2);

    This enables the block editor in the long description, but also removes your subtitle field (as it appears adding custom fields below the title isn’t an option with this product block editor enabled):


    For now, I’ve found work around and have added the subtitle field to the advanced tab within the product data panel:

    Using the follow two functions in my child theme:

    function add_pswc_subtitle_field_to_product_data_panel() {
    global $post;
    $subtitle = get_post_meta($post->ID, 'pswc_subtitle', true);
    ?>
    <div class="options_group">
    <p class="form-field">
    <label for="pswc_subtitle"><?php esc_html_e('Subtitle', 'my-child-theme'); ?></label>
    <input type="text" class="short" name="pswc_subtitle" id="pswc_subtitle" value="<?php echo esc_attr($subtitle); ?>" />
    <span class="description"><?php esc_html_e('Enter a subtitle for this product.', 'my-child-theme'); ?></span>
    </p>
    </div>
    <?php
    }
    add_action('woocommerce_product_options_advanced', 'add_pswc_subtitle_field_to_product_data_panel');

    function save_pswc_subtitle_field($post_id) {
    if (isset($_POST['pswc_subtitle'])) {
    update_post_meta($post_id, 'pswc_subtitle', sanitize_text_field($_POST['pswc_subtitle']));
    }
    }
    add_action('woocommerce_process_product_meta', 'save_pswc_subtitle_field(');

    Works well for me, but thought I’d share!

    Many thanks

    Thread Starter tictok

    (@tictok)

    That sounds great – looking forward to the update!

    Thanks again πŸ™

    Thread Starter tictok

    (@tictok)

    Hi, thanks for your reply.

    Sorry, you miss-understand what I meant, I probably wasn’t clear enough.
    I can add the block (as show in your video), no problem.

    The issue I have is that on the product edit screen for each product (posttype product) there is no field available to enter the subtitle value.

    If I turn off the block editor (for product edit screen), then the subtitle field is there just below the title when using the classic editor. However, all of our products use the block editor in their long description so the classic editor isn’t an option for us.

    I have found a work-around though. I also used AdminColumns Pro plugin, and have managed to add the subtitle post_meta field as an editable column in WooCommerce’s admin product listing.

    My product edit screen below, showing no sub-title field.

    Best regards

    Thread Starter tictok

    (@tictok)

    okay, solved. With a little shame and embaressment, but leaving this here in case it helps anyone else….

    Blocks were hidden in the Gutenberg/Block builder preferences. Guess I must have had Kadence installed sometime previously!

    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

    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 1 year, 11 months ago by tictok.
    tictok

    (@tictok)

    Bump.

    Any info, either way, would be really useful

    thanks

    Thread Starter tictok

    (@tictok)

    Hi, After further testing I have discovered that it looks like whether the Purchase event gets sent or not depends upon the browser being used.

    The Purchase event does get sent by your plugin if using Chrome. However, the Purchase event is not triggered when using Safari (17.2.1 macOS Sonoma 14.2.1). Will test other browsers too.

    I discovered this as had started to add my own JS script to the order-received page to send a Purchase event to the data layer. It worked as expected (when testing in Safari) but noticed when I tested in Chrome that two purchase events where being sent.

    Disabling my own script left just the single correct purchase event being added to the data layer in Chrome. But unfortunately still nothing in Safari.

    In the meantime, is there any way do disable your (gtm4wp) purchase event so that I can consistently/reliably send my own? I understand the data should look something like the following (depending upon products, price etc):

      event: "purchase",
      ecommerce: {
        currency: "GBP",
        transaction_id: "RJG-167656",
        affiliation: "",
        value: 1,
        tax: 0.17,
        shipping: 0,
        coupon: "",
        items: [
          {
            item_id: "ABCDE",
            item_name: "Test ABCDE",
            sku: "ABCDE",
            price: 1,
            stocklevel: null,
            stockstatus: "instock",
            google_business_vertical: "retail",
            item_category: "Planting &amp; Feeding",
            id: "ABCDE",
            quantity: 1
          }
        ]
      }


    If using Enhanced tracking do I need to include any user provider data in that payload, or will the data already in the data layer suffice?

    Many thanks
    Stef

    HI – apologies for jumping on the thread but also experiencing the same issue.

    Completely fresh GTM container after upgrading to latest version on GTM4WP.

    Stripe gateway.

    The is no ‘purchase’ event fired on either checkout or order received page and therefore my conversion tags are not being triggered.

    Trying the “Do not flag orders as being tracked” option did not change anything for me.

    The last event I can see in the data layer on checkout is “add_payment_info”.

    And on the order received page the event is: “gtm.load”. The data layers correctly contains all the order data, customer data, some payment details etc, but no purchase events.


    Thread Starter tictok

    (@tictok)

    Hiya James

    When Redis Object Cache Pro (https://objectcache.pro) detects that object-cache.php is not it’s own, the cache is disabled and the drop-in (object-cache.php) reported as invalid. It doesn’t suggest replacing object-cache.php.

    However, there is a button to enable the object cache again.

    Screenshot: https://snipboard.io/fjVKcY.jpg

    Clicking this replaces object-cache.php with its own version of the file, and the drop-in is temporarily reported as being Valid again.

    Unfortunately, it looks like the Performance plugin quickly replaces the object-cache.php file with it’s own again – once again disabling the cache and reporting as invalid.

    FYI, the other options and feature of the Redis Cache Pro plugin are also disabled… it’s not just a visual indicator.

    Hope that helps, but do let me know if I can share any more info

    Thanks

    Thread Starter tictok

    (@tictok)

    Hey James – many thanks for the info. All makes sense.

    This led me to investigate the Object Cache Pro plugin a little further.

    It appears to have a strict check (using get_plugin_data()) to see if the metadata at the top of the object-cache.php file matches what it expects (checking against it’s own copy of the file). Therefore, unfortunately, despite the include/require at the bottom of your plugin’s object-cache.php (which I guess would work in the majority of scenarios), the metadata at the top of your object-cache.php doesn’t match, causing Redis object cache Pro to flag the object-cache.php as invalid and disables itself.

    Suspect you will consider this as an edge-case, but thought I’d share anyway.

    Many thanks.

Viewing 15 replies - 1 through 15 (of 113 total)