Advertisement
lorro

WooCommerce - Set sale price to regular price

Dec 22nd, 2016
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2.   // set sale price = regular price if sale price is zero
  3.   // should set sale price to blank?
  4.   // needs additional error checking
  5.   // does not work for direct access to cart page
  6.   // intended as a framework for further development
  7.   // code goes in functions.php for your child theme
  8.   add_action ('woocommerce_before_shop_loop_item', 'check_sale_price', 40 );
  9.   add_action('woocommerce_before_single_product', 'check_sale_price', 40 );
  10.   function check_sale_price() {
  11.         $billing_first_name = get_post_meta(3834, '_billing_first_name', true );
  12.         print $billing_first_name;
  13.     global $product;
  14.     if ( $product->sale_price == '0' ) {
  15.       $price = $product->regular_price;
  16.       $product->sale_price = $price;
  17.       $product->price = $price;
  18.       global $wpdb;
  19.       $wpdb->get_results( 'UPDATE sa_postmeta SET meta_value='.$price.' WHERE meta_key="_sale_price" AND post_id='.$product->id, OBJECT );
  20.       $wpdb->get_results( 'UPDATE sa_postmeta SET meta_value='.$price.' WHERE meta_key="_price" AND post_id='.$product->id, OBJECT );
  21.     }
  22.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement