当我有一些GET参数时,如何在自定义页面上更改woocommerce产品价格?

时间:2019-06-19 15:40:06

标签: php wordpress woocommerce

我有具有正常价格和销售价格的woocommerce产品。 我有一些用户,这些用户来自带有GET参数的特殊网址,例如:

site.com/customcart/?emailsale=true

如何使普通用户以固定价格接收商品,而具有GET参数的用户可以享受折扣?

我已经尝试过此解决方案https://jeroensormani.com/disable-product-sale-prices-store-wide/

$order = wc_create_order();
$order->set_customer_id(is_numeric($args['customer_id']) ? absint($args['customer_id']) : 0);
$order->set_total(0, 'order_discount');
update_post_meta($order_id, '_payment_method', 'kassa-com');
update_post_meta($order_id, '_payment_method_title', 'Kassa.com');
$order->calculate_totals();

$posts = get_posts($args); //get product by user role

foreach ($posts as $post):
    setup_postdata($post);
    $product_id = get_the_ID();
    $_SESSION['product_id'] = $product_id;
    $price = round( get_post_meta(get_the_ID(), '_regular_price', TRUE) );
    $sale =  round( get_post_meta(get_the_ID(), '_price', TRUE) );
    $price_sale =  wc_format_sale_price($price, $sale) ;
    $product = wc_get_product($product_id);
    $price_html =  $product->get_price_html();
    echo $price_html;
endforeach;
wp_reset_postdata();
woocommerce_product_loop_end();

<form method="GET" action="<?php echo $order->get_checkout_payment_url(); ?>">
<input type="submit"  class="btn btn-pink right" value="Pay">
</form>

0 个答案:

没有答案