Support » Plugin: WPAdverts - Classifieds Plugin » Woocommerce order Products

  • Carin

    (@sparksfreebies)


    Hi Greg, 2 years ago you gave me this to order the List of Ad Products (woocommerce), but when I tried to add it to my new site, it broke my site, has anything changed?

    add_filter( "adext_wc_payments_products_new", "custom_wpadverts_product_sort" );
    add_filter( "adext_wc_payments_products_renew", "custom_wpadverts_product_sort" );
    
    function custom_wpadverts_product_sort( $args ) {
        $args["orderby"] = "ID";
        $args["order"] = "DESC";
    } );

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi,
    what do you mean by broke the site? Was there some error message? If so then what did the error say?

    One thing I see that would be problematic is that the function is missing “return” statement it should be

    
    add_filter( "adext_wc_payments_products_new", "custom_wpadverts_product_sort" );
    add_filter( "adext_wc_payments_products_renew", "custom_wpadverts_product_sort" );
    function custom_wpadverts_product_sort( $args ) {
        $args["orderby"] = "ID";
        $args["order"] = "DESC";
        return $args;
    } );
    
    Thread Starter Carin

    (@sparksfreebies)

    Hi Greg, That helps (before the site just went blank when I added without the return $args; I only know enough to be dangerous!)

    I added the amended code to my child theme functions.php but Woocommerce ad products are not sorted, I tried ASC and DESC but nothing changed. In order to work with my child theme, I have already replaced `
    $dirs[] = get_template_directory() . “/wpadverts/”;
    with
    $dirs[] = get_stylesheet_directory() . “/wpadverts/”;

     in override-templates.php
    found here, <a href="https://raw.githubusercontent.com/simpliko/wpadverts-snippets/master/override-templates/override-templates.php" rel="noopener" target="_blank">https://raw.githubusercontent.com/simpliko/wpadverts-snippets/master/override-templates/override-templates.php</a>
    I actually think my override-templates might be the issue because I just discovered this "Remove HTML" in my child functions.php is also not working correctly (html still available to person posting ad)
    

    // Remove HTML from AD description
    add_filter( “adverts_form_load”, function( $form ) {
    if( $form[“name”] != “advert” ) {
    return $form;
    }
    foreach( $form[“field”] as $k => $field ) {
    if( $field[“name”] == “post_content” ) {
    $form[“field”][$k][“filter”] = array( array( “name” => “strip_tags” ) );
    }
    }
    return $form;
    } );
    add_action( “init”, function( ) {
    adverts_form_add_filter( “strip_tags”, array(
    “description” => “strip_tags”,
    “callback” => “strip_tags”
    ) );
    } );`

    Plugin Author Greg Winiarski

    (@gwin)

    I am testing the code snippet and it seems to be working fine for me, it is sorting the pricings by ID in the [adverts_add]?

    Thread Starter Carin

    (@sparksfreebies)

    I moved both snippets the Parent theme and now Woocommerce Ad Order is working but remove HTML from Ad Description still not working https://www.screencast.com/t/0yWcCr1SLG. I would like for them both to be in the Child Theme, thats why I modified the overwrite-templates per your instruction-see above. Thanks!!.

    Plugin Author Greg Winiarski

    (@gwin)

    Both snippets should work the same in theme and child-theme functions.php file.

    You can also consider creating a blank plugin and put the snippets there, this is the best method to store the snippets https://wpadverts.com/blog/how-to-use-code-snippets-in-wordpress/

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