Transfer variations beetween the functions in WordPress (Woocommerce)

Question

I’m php and wordpress begginer.
I need help with explanation of transfer variations beetween the functions in WordPress (Woocommerce).


How can I use variable “$price” from function return_my_custom_price into the function “add_custom_price”?

I need to change value “10” into variable “$price”:

now —> $custom_price = 10 —> i need —> $custom_price = $price;


function return_my_custom_price($price, $product)
{
  $currency = get_woocommerce_currency();
  if ($product->id && $currency == 'USD') {
    if (($get_price = get_post_meta($product->id, '_custom_wholesale_usd', true))) {
        return $get_price;
    }
  }
  return $price;

}

add_filter('woocommerce_get_price', 'return_my_custom_price', 10, 2);
add_action( 'woocommerce_before_calculate_totals', 'add_custom_price' );

function add_custom_price( $cart_object ) {
    $custom_price = 10; // This will be your custome price  
    foreach ( $cart_object->cart_contents as $key => $value ) {
        $value['data']->price = $custom_price;
        // for WooCommerce version 3+ use: 
         $value['data']->set_price($custom_price);
    }
}

Thank you!

0
David 4 months 0 Answers 10 views 0

Leave an answer