• Resolved amstellodamois

    (@amstellodamois)


    Hey !

    I added the following snipet of code to a child theme to hide the price range on the top of the screen on variable products:

    add_action( 'woocommerce_before_single_product', 'my_remove_variation_price' );
    function my_remove_variation_price() {
      global $product;
      if ( $product->is_type( 'variable' ) ) {
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price' );
      }
    }

    I was happy with that solution because the price appeared after the variation choice: https://i.imgur.com/i7j0v3E.png

    Turns out this is the case only when variations have different prices. I fixed it by forcing this display with one line:
    add_filter( 'woocommerce_show_variation_price', '__return_true' );

    Now, even better: can I do the same for simple products?
    (i.e. have the price before the [Add to cart] button and not after the title)
    I would like it to look just like the woocommerce_show_variation_price with the little horizontal bar before

Viewing 1 replies (of 1 total)
  • Thread Starter amstellodamois

    (@amstellodamois)

    Well, I thought it was out of my reach but I did it:

    //Move price below short description on simple products
    add_action( 'woocommerce_before_single_product', 'my_move_simple_price' );
    function my_move_simple_price() {
      global $product;
      if ( $product->is_type( 'simple' ) ){
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
        remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
        add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 10 );
        add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 20 );
      }
    }

    I don’t have the horizontal bar but I don’t really need it. In fact, I’ll probably try to remove it (with the “CLEAR” link) on variable products.

Viewing 1 replies (of 1 total)
  • The topic ‘Always show price before the Add to cart button’ is closed to new replies.