Forum Replies Created

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • in reply to: Getting the Price to appear in text box #30115

    To be able to sort by price, the minimum price is saved as the price. But this should not be displaying in the loop unless the loop displays $product->get_price() instead of $product->get_price_html(). The latter has the filters that NYP attaches to. ( Also possible that something is already filtering the woocommerce_get_price_html )

    I still believe that variable products are over-complicating things and that switching to simple products will save a lot of headaches.

    in reply to: Getting the Price to appear in text box #30059

    If Suggested Price: $10 is not appearing for the simple product, then something must be interfering, either the theme or another plugin. NYP is set to filter the price html via the woocommerce_get_price_html filter, but if your loop is not calling:

    $product->get_price_html()

    to display the price HTML, then there’s nothing I can do on my end. I would recommend that you take a look at how Name Your Price behaves under default circumstances… ie: only WooCommerce and Name Your Price enabled and using a default theme such as Twenty Nineteen (or Storefront). This will give you a good sense of how Name Your Price is expected to behave so that when it doesn’t behave that way you will know where to look.

    I really think that Simple Products will be easiest in the long run as my other code is hackish, non-performant, and a workaround for something that could be resolved by switching to Simple Product types.

    My script above does not include the “From:” string, but you can add it:

    $html = wc_get_price_html_from_text() . WC_Name_Your_Price_Helpers::get_suggested_price_html( $child_id );

    I can’t speak for the Phone Orders developers but if it were me, I would not add my script to their plugin. It’s site-specific and so belongs in a custom plugin on your site (or possibly a child theme).

     

    in reply to: Getting the Price to appear in text box #30052

    Rizwan,

    However as you can see the price is From: £0.00. It is not pulling the suggested price.

    It never has for variable products. Variable product price strings are tricky and I’ve tried to follow along with the WooCommerce approach of showing “From: $X” where X is the lowest price… in NYP’s case the lowest minimum. Which has it’s own problems if there is no minimum.

    Could you make do with each product being a simple product in lieu of a variable product? They are a lot easier to work with. You’ll automatically get a “Suggested Price” string which can be modified from the settings.

    Poster with text below reading "suggested price: $100"

    Since your variations don’t seem to change the price at all, perhaps the info would be better stored as a Product Addon style field.

    As a variable product the price string is a lot more difficult to generate and NYP hasn’t been stashing it’s suggested prices in the price transients. However, if the suggested amounts are the same across all variations you could perhaps get away with the following, though it may not be very performant. You only have 3 variations, so perhaps get_children() won’t be that slow.

     

    /**
    * Change price string for Variable Products .
    */
    function kia_filter_variable_product_price_html( $html, $product ) {
      $children = $product->get_children();
      if( ! empty( $children) ) {
        foreach( $children as $child_id ){
          $html = WC_Name_Your_Price_Helpers::get_suggested_price_html( $child_id );
          break;
        }
      }
      return $html;
    }
    add_filter( 'woocommerce_variable_nyp_html', 'kia_filter_variable_product_price_html', 10, 2 );

     

    in reply to: Getting the Price to appear in text box #30031

    Harry,

    This seems like a different issue…but it’s possible to do if you’ve set a suggested price of $10 even though that’s lower than the minimum price of $25. The plugin will show a warning in the admin when you do this, but it doesn’t stop you. You will then fall into the known accessibility bug of not being able to click on the add to cart button until you click outside of the text input. I’m working on revising that in NYP 3.0, but for now the best way to avoid it is to provide a suggested price that is higher than the minimum.

    By reading the magnific popup source code I was able to determine the eventhandler they use is named mfpOpen. With that information is possible to initialize the NYP scripts on this event.

    Here’s a plugin that should add compatibility:

    https://gist.github.com/helgatheviking/bc372086690e5d315e7aced3aeb1062b

    You can see it working here on the Variable NYP product:

    https://wp5-helgatheviking.c9users.io/shop/page/3/

    Cheers,

    -kathy

     

     

    in reply to: Getting the Price to appear in text box #30023

    Harry,

    Here’s what a variable product with a name your price-enabled variations is meant to look like on the single product page:

    Variable NYP

    The input will show the suggested price for that variation. If there’s no suggested price set, it will try to show the minimum price, unless “hide minimum” is enabled. Since it’s possible for every variation to be Name Your Price-enabled and therefore have different suggested/minimum prices… the input’s value is set via Javascript (specifically jQuery). And finally, if you try to enter a price that is below the minimum you will get an error notice.

    So if this is not happening I would guess that you haven’t initialized the Javascript function properly. Because the input is not in the DOM when the page loads the NYP script won’t _do_ anything. As I’ve written above, it must be initialized on some event that occurs when the popup opens.

    Sidenote: you seem to have some PHP notices in your product image template.

    Notice: Undefined variable: post_thumbnail_id in /home/ubuntu/workspace/wp-content/themes/claue/core/libraries/vendors/woocommerce/templates/single-product/product-image.php on line 103

    Notice: Undefined variable: post_thumbnail_id in /home/ubuntu/workspace/wp-content/themes/claue/core/libraries/vendors/woocommerce/templates/single-product/product-image.php on line 111

    Notice: Undefined variable: zoom in /home/ubuntu/workspace/wp-content/themes/claue/core/libraries/vendors/woocommerce/templates/single-product/product-image.php on line 118

    in reply to: Getting the Price to appear in text box #30001

    Hi Harry and Rizwan,

    The snippet for enqueing the NYP script should have been:

     

    function kia_load_nyp() {
        if( function_exists( 'WC_Name_Your_Price' ) ){
            WC_Name_Your_Price()->display- >nyp_scripts();
        }
    }
    add_action( 'wp_enqueue_scripts', 'kia_load_nyp', 30 );

    My apologies, I was away from my keyboard when typing that, but can confirm that it will load the NYP script everywhere. Please avoid copying the NYP script into your theme. There’s no reason to do this. It will lock users into outdated versions of the script and set me up for difficult support tickets down the road trying to sort out why the script may not be behaving properly.

    <?php do_action( ‘woocommerce_quickview_before_ thumbnail’ ); ?>

    is not satisfactory for adding the custom JavaScript listener since it’s a PHP hook, though maybe if that’s only displayed in the popup itself, you could print the relevant script there?

        $( 'body' ).find( '.cart:not(.cart_group)' ).each( function() {
           $( this ).woocommerce_nyp_update();
        } );

    And possibly change body to whatever the popup is? I’m not sure. I’m more familiar with the custom jQuery event/listener setup that I use for compatibility with QuickView and Composite Products. So I think you’ll need something like:

    $(‘body’).trigger(‘quick-view- displayed’);

    somewhere in your Javascript when the popup opens. Magnificent Popups has an open callback, see the API:https://dimsemenov.com/plugins/magnific-popup/documentation.html#api

    perhaps you could add a custom event trigger there. Or their docu says “all Magnific Popup events are also dispatched using triggerHandler on target element (or to document if the element doesn’t exist).” so the custom event may already be there, I just don’t know what it’s called.

    Once you have a custom Javascript event that fires when the popup is loaded you can duplicate what I am doing for Quick View compatibility and reinitialize the NYP script now that the price input is in the DOM.

    /**
    * Run when Quick view item is launched.
    */
    $( 'body' ).on( 'your-custom-event', function() {
        $( 'body' ).find( '.cart:not(.cart_group)' ).each( function() {
           $( this ).woocommerce_nyp_update();
        } );
    } );
    
    
    

    That’s all I can think of from my side to explain how NYP works, but let me know if you have any further questions.

     

    Cheers,

    -Kathy

    Lead Developer: Name Your Price

Viewing 6 posts - 1 through 6 (of 6 total)