Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Aslam Doctor

    (@aslamdoctor)

    @fabioweb there is a known issues with a conflict with elementor plugin and I am working on a fix for new version of my plugin. In the mean time, please try adding this PHP code using WPCode plugin. If you need any assistance, please email me and I will guide you how to add it.

    <?php
    /**
    * RWPP Elementor Support
    * Enables category-based sorting for Elementor WooCommerce Products widget
    *
    * Requires: "Order By" set to "Menu Order" in Elementor widget settings
    */

    // Initialize global state
    $GLOBALS['rwpp_elementor_active'] = false;
    $GLOBALS['rwpp_elementor_term_id'] = null;

    // Intercept shortcode query to detect category and activate filters
    add_filter( 'woocommerce_shortcode_products_query', function( $query_args, $attributes ) {

    // Only apply when ordering by menu_order
    $orderby = isset( $query_args['orderby'] ) ? $query_args['orderby'] : '';
    if ( strpos( $orderby, 'menu_order' ) === false ) {
    return $query_args;
    }

    // Find term_id from tax_query
    $term_id = null;
    if ( isset( $query_args['tax_query'] ) ) {
    foreach ( $query_args['tax_query'] as $tax ) {
    if ( is_array( $tax ) && isset( $tax['taxonomy'] ) && $tax['taxonomy'] === 'product_cat' && ! empty( $tax['terms'] ) ) {
    $terms = $tax['terms'];
    $first_term = is_array( $terms ) ? $terms[0] : $terms;
    $field = isset( $tax['field'] ) ? $tax['field'] : 'term_id';

    if ( $field === 'term_id' || $field === 'id' || is_numeric( $first_term ) ) {
    $term_id = intval( $first_term );
    } else {
    $term = get_term_by( $field, $first_term, 'product_cat' );
    $term_id = $term ? $term->term_id : null;
    }
    break;
    }
    }
    }

    if ( ! $term_id ) {
    return $query_args;
    }

    // Activate filters globally
    $GLOBALS['rwpp_elementor_active'] = true;
    $GLOBALS['rwpp_elementor_term_id'] = $term_id;

    return $query_args;
    }, 5, 2 );

    // JOIN filter - adds custom table join for sorting
    add_filter( 'posts_join', function( $join, $query ) {
    if ( empty( $GLOBALS['rwpp_elementor_active'] ) || empty( $GLOBALS['rwpp_elementor_term_id'] ) ) {
    return $join;
    }

    // Only apply to product queries
    $post_type = $query->get( 'post_type' );
    if ( $post_type !== 'product' && ! ( is_array( $post_type ) && in_array( 'product', $post_type ) ) ) {
    return $join;
    }

    // Prevent duplicate joins
    if ( strpos( $join, 'rwpp_order' ) !== false ) {
    return $join;
    }

    global $wpdb;
    $term_id = $GLOBALS['rwpp_elementor_term_id'];
    $table = $wpdb->prefix . 'rwpp_product_order';

    $join .= " LEFT JOIN {$table} AS rwpp_order ON {$wpdb->posts}.ID = rwpp_order.product_id AND rwpp_order.category_id = " . absint( $term_id );

    return $join;
    }, 999, 2 );

    // ORDER BY filter - applies custom sort order
    add_filter( 'posts_orderby', function( $orderby, $query ) {
    if ( empty( $GLOBALS['rwpp_elementor_active'] ) || empty( $GLOBALS['rwpp_elementor_term_id'] ) ) {
    return $orderby;
    }

    // Only apply to product queries
    $post_type = $query->get( 'post_type' );
    if ( $post_type !== 'product' && ! ( is_array( $post_type ) && in_array( 'product', $post_type ) ) ) {
    return $orderby;
    }

    // Only modify if it's a menu_order query
    if ( strpos( $orderby, 'menu_order' ) === false ) {
    return $orderby;
    }

    global $wpdb;
    return "COALESCE(rwpp_order.sort_order, {$wpdb->posts}.menu_order, 9999) ASC, {$wpdb->posts}.post_title ASC";
    }, 999, 2 );

    // Cleanup at end of page
    add_action( 'wp_footer', function() {
    $GLOBALS['rwpp_elementor_active'] = false;
    $GLOBALS['rwpp_elementor_term_id'] = null;
    }, 999 );
    Thread Starter fabioweb

    (@fabioweb)

    I insert script, position everywhere but i still see the same ordering..

    Plugin Author Aslam Doctor

    (@aslamdoctor)

    @fabioweb would it be possible for you to get me a temporary access to your website so that I can look into that and identify? Many times there are other plugins that can be conflicting with this plugin.
    You can contact me from here and we will look into this further.

Viewing 3 replies - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.