• Resolved andytom

    (@andytom)


    Wrote a function for changing the price of goods for woocommerce

    add_action('woocommerce_get_price','change_price_regular_member', 10, 2);
    function change_price_regular_member($price, $productd){
      global $product;
      $product_id=$product->id;
      $current_price = (int)get_field('markup_for_the_goods', $product_id);
      $prise = ($price*$current_price/100)+$price;
        return $prise;
    }

    I use custom fields ACF.
    In the product card everything is perfectly displayed, but when added to the basket, the base price is entered there, and not my altered one.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Are you changing the price for the product passed from the filter or you are changing the price of the global product?

    add_action( 'woocommerce_get_price', 'change_price_regular_member', 10, 2 );
    /**
     * @param            $price
     * @param WC_Product $product
     *
     * @return float
     */
    function change_price_regular_member( $price, $product ) {
    	$mark_up = (int) get_field( 'markup_for_the_goods', $product->get_id() );
    	$price   = ( $price * $mark_up / 100 ) + $price;
    	
    	return $price;
    }

    We haven’t heard back from you in a while, so I’m going to mark this as resolved. If you have any further questions, you can start a new thread.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘mark-up of the goods’ is closed to new replies.