Dynamicly changing products pricing

  • Solved
  • Posted 2 months ago

Hey guys, we made this snippet here,

add_action( ‘init’, function() {

IF ( isset( $_GET[ ‘dev-update-price’ ] ) ) {

$donation_product_id = 13515;

$price = $_GET[ ‘dev-update-price’ ];

$post = \Voxel\Post::get( $donation_product_id );

if ( ! $post ) {
return;
}

$product_field = $post->get_field( ‘product’ );

$product = $product_field->get_value();

$product[ ‘base_price’ ][ ‘amount’ ] = $price;

$product_field->update( $product );

echo ‘price updated’;
exit;
}

}, 10 );

is this the best way to implement like a ‘name your price’ feature to a product.

basically, our plan is to trigger the dynamic price change on the cart and restore it back to its base price.

basically this plugin here to replicate its feature in voxel.

https://woocommerce.com/products/advanced-pay-what-you-want/