• Resolved allrelative

    (@allrelative)


    Hi,

    I would like to know if there is a way to establish the order that the pricing options appear in. I have either two or three, depending.

    I would like ‘Free’ to appear first, and then the other two in order of price from low to high. Is there any way to implement this?

    thank you!

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

    (@gwin)

    You can use the adverts_form_load filter for this

    
    add_filter( "adverts_form_load", "my_adverts_form_load", 2000 );
    function my_adverts_form_load( $form ) {
      if( $form["name"] != "advert" ) {
        return $form;
      }
      $opts = array(
          array( "value" => 100, "text" => "" ),
          array( "value" => 200, "text" => "" ),
          array( "value" => 300, "text" => "" )
      );
      foreach( $form["field"] as $key => $field ) {
        if( $field["name"] == "payments_listing_type" ) {
            $form["field"][$key]["options"] = $opts;
        }
      }
      return $form;
    }
    

    In the code 100 should be the actual ID of pricing you want to show first, 200 an ID of pricing you want to show as second and 300 id of a pricing displayed as third.

    It works fine on the new ads, but do you have codes for renewals too?

    Plugin Author Greg Winiarski

    (@gwin)

    I understand you want to do this for the WooCommerce integration? If so then the would need to change line

    
    if( $form["name"] != "advert" ) {
    

    to

    
    if( $form["name"] != "advert-renew" ) {
    

    and of course the $opts array to use proper options.

    Hi Greg,

    Yes, I am using it with WooCommerce.

    I tried with this, but only got a white screen….!

    add_filter( “adverts_form_load”, “my_adverts_form_load”, 2000 );
    function my_adverts_form_load( $form ) {
    if( $form[“name”] != “advert-renew” ) {
    return $form;
    }
    $opts = array(
    array( “value” => 385, “text” => “” ),
    array( “value” => 854, “text” => “” ),
    array( “value” => 389, “text” => “” ),
    array( “value” => 392, “text” => “” )
    );
    foreach( $form[“field”] as $key => $field ) {
    if( $field[“name”] == “payments_listing_type” ) {
    $form[“field”][$key][“options”] = $opts;
    }
    }
    return $form;
    }

    I just checked the error log…

    [11-Dec-2017 09:46:32 UTC] PHP Fatal error: Cannot redeclare my_adverts_form_load() (previously declared in wp-content/themes/enfold-child/functions.php:186) in /wp-content/themes/enfold-child/functions.php on line 221.

    The declare on line 186 is for sorting prices for the new ads.

    Thanks 🙂

    Plugin Author Greg Winiarski

    (@gwin)

    You should be able to fix this by changing the first two lines of code from your last message from

    
    add_filter( "adverts_form_load", "my_adverts_form_load", 2000 );
    function my_adverts_form_load( $form ) {
    

    to

    
    add_filter( "adverts_form_load", "my_adverts_form_load_renew", 2000 );
    function my_adverts_form_load_renew( $form ) {
    

    It works – thanks 😉

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

The topic ‘setting order for pricing’ is closed to new replies.