How to change style at product page
-
When editing a product, there is no way to change the styling of the donation block. Since this is done to insert a block on other pages. For example, I like the stylization when everything is on one page. How to make the same block on the product page?
-
Hi kassilukraine,
thanks for reaching out.
It’s currently not possible to change the template of the product page donation form without some custom implementation, sorry :/Best,
JonasOkay, I already found another solution. I did the checkout bypass. in which an ajax handler is created that programmatically creates an order and sends the person after clicking on donat directly to the payment gateway. everything is returned successfully, the only problem I encountered is that when setting the status to “completed”, the total amount of donations changes not to the amount of the donation, but to the amount of the cost of the woocommerce product. and I can’t yet understand why. Perhaps you can help me with this?
Thank you in advance for your response.add_action('wp_ajax_custom_create_order', 'custom_create_order_callback'); add_action('wp_ajax_nopriv_custom_create_order', 'custom_create_order_callback'); function custom_create_order_callback() { // nonce check_ajax_referer('custom_ajax_nonce', 'security'); // get data by post $product_id = isset($_POST['product_id']) ? intval($_POST['product_id']) : 0; $donation_amount = isset($_POST['donation_amount']) ? floatval($_POST['donation_amount']) : 0; // get user data $current_user = wp_get_current_user(); $user_email = $current_user->user_email; $user_first_name = $current_user->first_name; $user_last_name = $current_user->last_name; $user_phone = get_user_meta($current_user->ID, 'billing_phone', true); // validation if (!$product_id || $donation_amount <= 0) { wp_send_json_error(['message' => 'Invalid order details.']); return; } $product = wc_get_product($product_id); if (!$product) { wp_send_json_error(['message' => 'Product not found.']); return; } $order = wc_create_order(); $order->add_product($product, 1); $item = new WC_Order_Item_Fee(); $item->set_name("Donation"); $item->set_amount($donation_amount); $item->set_total($donation_amount); $order->add_item($item); // Установка данных заказа $order->set_total($donation_amount); $order->set_payment_method('morkva-liqpay'); $order->update_status('pending', 'Order awaiting payment'); // Добавление данных пользователя в заказ $order->set_billing_email($user_email); $order->set_billing_first_name($user_first_name); $order->set_billing_last_name($user_last_name); $order->set_billing_phone($user_phone); $order->calculate_totals(); $order->set_total($donation_amount); $order->save(); $available_gateways = WC()->payment_gateways->payment_gateways(); $gateway = isset($available_gateways['morkva-liqpay']) ? $available_gateways['morkva-liqpay'] : false; if (!$gateway) { wp_send_json_error(['message' => 'Payment gateway not found.']); return; } if (!$gateway->is_available()) { wp_send_json_error(['message' => 'Payment gateway is unavailable.']); return; } $order_id = $order->get_id(); $payment_gateways = WC()->payment_gateways->get_available_payment_gateways(); if (isset($payment_gateways['morkva-liqpay'])) { $gateway = $payment_gateways['morkva-liqpay']; $result = $gateway->process_payment($order_id); if ($result['result'] == 'success') { wp_send_json_success(['redirect' => $result['redirect']]); } else { wp_send_json_error(['message' => 'Error processing payment.']); } } else { wp_send_json_error(['message' => 'Payment gateway not found.']); } }
so total donation amount not change after “completed” order.
maybe i need add some hook after i got result gatway?
-
This reply was modified 1 year, 1 month ago by
kassilukraine.
I talk about product page and the your donation plugin at the product page. Coz if i use shortcode at page, all done. total amount updates
Only a day later it dawned on me that the cost of the goods should be equal to the donation amount. But in order to programmatically change the cost of a product during the process of creating an order, you need to change a lot. Because of this, I realized that in fact a discount is applied, and creating custom coupons is not such a complicated process, so I got the cost of the product and created a coupon equal to the difference between the cost of the product and the donation amount on the fly.
Perhaps this solution will be useful to someone
// Getting the cost of the product $product_price = $product->get_price(); // Create a coupon $coupon_amount = $product_price - $donation_amount; $coupon_code = uniqid('donation_coupon_'); // Generate a unique coupon code $coupon = new WC_Coupon(); $coupon->set_code($coupon_code); $coupon->set_discount_type('fixed_cart'); $coupon->set_amount($coupon_amount); $coupon->set_individual_use(true); $coupon->save(); // Generate a unique coupon code $order->apply_coupon($coupon_code);
Hi kassilukraine,
thanks for sharing your solution ??
Best,
JonasYou’re welcome @flinnn.
I also had to fix a lot of lines in the plugin style files, and now I’m afraid of updating. It would be wonderful in future updates to provide the opportunity to also insert templates for this plugin into the theme so that you can update the plugin and not worry that your many hours of work will not go to waste.
Since this is organized in the same woocommerce, if there are no template files in the theme, then the standard ones are taken from the plugin, and then templates or part of them from the theme files are used.
I would also like to be able to manually add the donation amount in orders. If, for example, we were paid to a bank account or in another way, and not using a payment gateway, in order to take this amount into account in the overall progress of the donation.
-
This reply was modified 1 year, 1 month ago by
- The topic ‘How to change style at product page’ is closed to new replies.