logo
down
shadow

Change price location in Woocommerce Single Product Layout


Change price location in Woocommerce Single Product Layout

By : 自我与修养
Date : November 21 2020, 11:01 PM
I wish this help you If you have a look to the WooCommerce content-single-product.php template file in this extract:
code :
<?php
    /**
     * woocommerce_single_product_summary hook.
     *
     * @hooked woocommerce_template_single_title - 5
     * @hooked woocommerce_template_single_rating - 10
     * @hooked woocommerce_template_single_price - 10
     * @hooked woocommerce_template_single_excerpt - 20
     * @hooked woocommerce_template_single_add_to_cart - 30
     * @hooked woocommerce_template_single_meta - 40
     * @hooked woocommerce_template_single_sharing - 50
     */
    //do_action( 'woocommerce_single_product_summary' );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );


Share : facebook icon twitter icon
Sample Product, change location of Price | Wordpress Woocommerce

Sample Product, change location of Price | Wordpress Woocommerce


By : Ferdinand Ribbink
Date : March 29 2020, 07:55 AM
Hope this helps In the below code, you are overwriting the WooCommerce hook inclusion/priority order. So the price will be included after woocommerce_template_single_excerpt which has a priority value of 20
Include the following code in functions.php.
code :
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );

add_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 25 );
Change price location on single product pages

Change price location on single product pages


By : Muhammad qodri
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This will work just for simple products as variable products displays already their live price above the Add-to-cart button.
This is the code you need:
code :
function changing_price_location_for_simple_products(){
    global $product;

    if($product->is_type('simple')) // Only for simple products (thanks to helgathevicking)
    {
        remove_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 10);
        add_action('woocommerce_single_product_summary', 'woocommerce_template_single_price', 25);
    }
}
add_action('woocommerce_before_single_product', 'changing_price_location_for_simple_products');
Calculate price and display on WooCommerce product single page under price (simple price, variable price)

Calculate price and display on WooCommerce product single page under price (simple price, variable price)


By : user3079045
Date : March 29 2020, 07:55 AM
will be helpful for those in need This code will display the value or content before Add to Cart button in woocommerce product page.
code :
        add_action( 'woocommerce_single_product_summary', 'show_emi', 20 );
      function show_emi() {
       global $product; 
       $id = $product->get_id();
        $product = wc_get_product( $id );
        $a=$product->get_price();
        $b  = 5.15464;
        $c = 100;
        $d = $a * $b;
        $total = $d/$c;
          echo $total;
      }
Change and save the product price in Woocommerce single product pages

Change and save the product price in Woocommerce single product pages


By : user3210034
Date : March 29 2020, 07:55 AM
Does that help Updated
First, you are not using the right hook for that as it requires to be trigger before the page load.
code :
add_action( 'template_redirect', 'change_and_save_product_price' );

function change_and_save_product_price() {
    if ( get_post_type() === "product" ){ // or use: is_product()
        // HERE your new product price
        $new_price = 100;

        // Get an instance of the WC_Product Object
        $product = wc_get_product( get_the_id() );

        if ( $product->is_type('simple') ) {
            // Get current price (if needed)
            // $price = $product->get_price();

            // Set the new price
            $product->set_regular_price( $new_price );
            $product->set_price( $new_price );

            // (optionally) reset sale price => uncomment below
            // $product->set_sale_price( false );

            // Save to database refresh refresh caches
            $product->save();
        }
    }
}
Display specific product attribute in Woocommerce single product pages below price

Display specific product attribute in Woocommerce single product pages below price


By : MD. SHAHI ISLAM
Date : March 29 2020, 07:55 AM
help you fix your problem The following will display a specific product attribute label name + values under the price in single product pages only if it has a value.
This can be done using WC_Product method get_attribute().
code :
add_action( 'woocommerce_single_product_summary', 'product_attribute_after_price', 15 );
function product_attribute_after_price () {
    global $product;

    // HERE add your product attribute SLUG or taxonomy
    $attribute_slug = 'color';

    $taxonomy = strpos($url, 'blog') !== false ? $attribute_slug : 'pa_' . $attribute_slug;
    $attribute_name = get_taxonomy( $taxonomy )->labels->singular_name;
    $term_name = $product->get_attribute( $taxonomy ); // The value

    if( empty($term_name) ) return; // Exit if empty value

    // If not empty we display it
    $output  = '<div class="product-attribute '.$taxonomy.'"><p>';
    $output .= '<strong> '.$attribute_name.'</strong>: ';
    $output .= '<span> '.$term_name.'</span>';
    echo $output . '</p></div>';
}
Related Posts Related Posts :
  • Set up Phalcon 3.0.x with Php 7.0.x in ubuntu16.04
  • Server picking up old files
  • CSS loading after HTML loads
  • Getting an error for double and boolean even boolean given
  • Create shipment using fedex api (php)
  • How to get the variable value from one controller to another controller?
  • Bind doesn't work on User model
  • Sort JSON date by date - PHP
  • apache log is filled with erros and warnings almost 25 gb each time
  • Chrome adding tags (#shadow-root (open))
  • Split an array based on the value of another array
  • CodeIgniter Calendar Preferences template not working
  • .htaccess mode rewrite does not affect page url
  • PHP Laravel 5 : Trait not found
  • php count values column
  • Ajax POST not recognised as part of current guest session, Laravel 5.3
  • Why is my contact form PHP script not working? No error log
  • Sorting racers / players by places
  • cURL empty request data if https connection
  • PHP/MYSQL - Multiple connections to the same database?
  • PHP: Handle only parents on array
  • PHP IF How to include multiple conditions?
  • Basic PHP contact form receiving email but no message
  • Turn string to array in PHP (all data recorder as string)
  • Sorting issues with mySQL JOIN
  • Get keys from multidimentional array by value
  • php accessing variables in constructor from included file
  • Mysqli can't insert multiple rows
  • PHP Substracting 1 day from date string php doesnt work
  • How to know the column name on yii2 Gridview
  • How to preg_match() a variable from file_get_contents()
  • How can we use search conditions (.. and ..or..) for columns instead of rows in mysql?
  • Ternary operator - unexpected behavior
  • I cant retrieve the value of $_COOKIE['mycookiename'] when request sent to server with ajax
  • Message could not be sent.Mailer Error: SMTP connect() failed
  • Get error before they execute the error message function
  • Convert CI_Model to JSON and then Send to AJAX
  • How to convert Localtime to user seleted timezone in php
  • fopen to add variable to file
  • Values from checkbox group are correct in querystring, but are not arrays in the $_GET variable
  • Is die function accept only strings?
  • Remove category from woocommerce loop on custom shop page
  • Perform word match in a String until another word is found in the String
  • Codeigniter callbacks affecting required validation
  • PHP execution in a hidden way
  • Adding data to DB fails without an error - Laravel
  • Php pdo iterate with sequence
  • How to get the route its structure in Laravel
  • Laravel HTTP status code "1" is not valid error
  • execute a python code from php and take the return value back to the php code example
  • Cant share Auth::check() in App\Http\Controllers\Controller via view()->share
  • Wordpress AJAX: Get a function as Json response
  • Use custom fields in registration email for Wordpress Cimy
  • Swift_SmtpTransport phalcon
  • How to retrieve data from multiple Google Analytics accounts using Google API?
  • Add xmlhttprequest inside a PHP post request
  • sorting mongo regex query in php
  • Can not leverage browser caching in codeigniter using htaccess
  • Create descendant class based on Eloquent model
  • XML PHP Login Error
  • shadow
    Privacy Policy - Terms - Contact Us © soohba.com