Skip to content

Instantly share code, notes, and snippets.

View vanbo's full-sized avatar

Ivan Andreev vanbo

View GitHub Profile
@vanbo
vanbo / wc-cancel-failed-payment-orders
Last active July 15, 2020 21:06
WooCommerce Cancel Failed Payment Orders
/**
* Cancel all failed orders after held duration
* The method is adapted from the WooCommerce "wc_cancel_unpaid_orders" function and uses 'woocommerce_cancel_unpaid_orders' schedule hook
*
* Code location: Add the code to your "child-theme/functions.php" file
*
* Requirements: "Product > Inventory > Manage Stock" enabled, and time set in the "Product > Inventory > Hold stock (minutes)" setting.
*/
function vanbo_cancel_failed_orders() {
$held_duration = get_option( 'woocommerce_hold_stock_minutes' );
@vanbo
vanbo / wc-borica-filter-payment-request
Created July 29, 2020 13:20
WC Borica Filter Payment Request
/**
* NOTE: Add the code to your "child-theme/functions.php" file
*/
add_filter( 'wc_borica_form_request_parameters', 'vanbodevelops_filter_borica_request', 10, 3 );
function vanbodevelops_filter_borica_request( $params, $order, $gateway ) {
// NOTE: Use each block as needed.
// 1. Change the Borica payment page language
// 'BG' - bulgarian, 'EN' - english
$params['language'] = 'EN';
@vanbo
vanbo / wc-trustcommerce-add-operator-id-requests
Created August 18, 2020 12:24
WooCommerce TrustCommerce add operator ID to requests
/**
* IMPORTANT: Add the code to your "child-theme/functions.php" file
*/
add_filter( 'wc_trustcommerce_process_single_payment_request', 'vanbo_tc_add_operator_to_requests', 10 );
add_filter( 'wc_trustcommerce_process_profile_payment_request_request', 'vanbo_tc_add_operator_to_requests', 10 );
add_filter( 'wc_trustcommerce_create_customer_profile_request', 'vanbo_tc_add_operator_to_requests', 10 );
add_filter( 'wc_trustcommerce_update_customer_profile_request', 'vanbo_tc_add_operator_to_requests', 10 );
add_filter( 'wc_refund_payment_request_trustcommerce', 'vanbo_tc_add_operator_to_requests', 10 );
add_filter( 'wc_capture_payment_request_trustcommerce', 'vanbo_tc_add_operator_to_requests', 10 );
@vanbo
vanbo / wc-borica-work-around-polylang-language-storage
Created September 14, 2020 12:14
WC Borica - Work around Polylang language storage
/**
* IMPORTANT: Past this snippet to your "child-theme\functions.php" file.
*/
add_action( 'init', 'vanbo_store_polylang_language', 99 );
/**
* Saves the Polylang last used language by the current user
*/
function vanbo_store_polylang_language() {
if ( ! function_exists( 'WC' ) || ! WC()->session ) {
@vanbo
vanbo / wc-epaybg-no-pay-page-reload-after-form-submit
Last active September 12, 2022 13:11
WooCommerce ePaybg: Do not allow Pay page reload after customer is sent to ePaybg
add_action( 'woocommerce_receipt_epaybg', 'vanbo_initiate_epaybg_request_hooks', 9 );
/**
* Replaces the gateway original action with our own
*/
function vanbo_initiate_epaybg_request_hooks() {
$gateway = vanbo_get_epaybg_gateway();
if ( false == $gateway ) {
return;
}
@vanbo
vanbo / wc-paytrace-block-card-types-js
Last active October 19, 2020 17:48
WC Paytrace block card types on checkout
/**
* NOTE: Add this snippet to your "child-theme\functions.php" file
*/
add_action( 'wp_footer', 'vanbo_add_block_script_to_footer', 9999 );
function vanbo_add_block_script_to_footer() {
?>
<script>
(function ($) {
/**
@vanbo
vanbo / wc-psigate-include-shipping-for-free-orders
Last active January 13, 2021 17:08
WooCommerce Psigate include the shipping in the order total for free orders
/**
* Add to your "themes/child-theme-folder/functions.php" file
*/
add_filter( 'wc_psigate_process_credit_card_payment_parameters', 'vanbo_combine_shipping_in_total', 10, 2 );
function vanbo_combine_shipping_in_total( $parameters, $order ) {
$total = number_format( ( $order->get_total() - WC_Compat_PsiGate::get_total_shipping( $order ) - $order->get_total_tax() ), 2, '.', '' );
// If the total is 0
if ( 0 >= $total ) {
// Subtotal will equal the order total
@vanbo
vanbo / wc-pay360-modify-request-register
Created February 17, 2021 09:10
WC Pay360 Modify Request 'register'
/**
* NOTЕ: Add the code to your "themes\child-theme\functions.php" file
*/
add_filter( 'pay360_hosted_cashier_get_parameters', 'vanbodevelops_do_not_register_profile', 10, 3 );
function vanbodevelops_do_not_register_profile( $args, $order, $get_gateway ) {
// Send the 'registered' parameter as false,
// so Pay360 will not create a profile for the customer in their system.
if ( ! empty( $args['customer'] ) ) {
$args['customer']['registered'] = false;
}
@vanbo
vanbo / woocommerce-pay360-replace-checkout-icons
Last active February 23, 2021 13:07
WooCommerce Pay360 replace checkout icons
/**
* IMPORTANT: Place the snippet inside your "wp-content\themes\child-theme\functions.php" file
*/
/**
* Replace the Pay360 image in the checkout icon
*/
add_filter( 'woocommerce_pay360_icon', 'vanbodevelops_pay360_icon', 10 );
function vanbodevelops_pay360_icon( $image ) {
return WC_Pay360::plugin_url() . '/pay360-logo.png';
@vanbo
vanbo / woocommerce psigate limit transaction attempts
Last active March 22, 2021 08:37
WooCommerce Psigate limit transaction attempts
/**
* Add to "wp-content\themes\child-theme\functions.php" file
*/
add_filter( 'wc_psigate_process_acc_manager_payment_parameters', 'vanbodevelops_filter_acc_parameters', 10, 2 );
add_filter( 'wc_psigate_process_credit_card_payment_parameters', 'vanbodevelops_filter_acc_parameters', 10, 2 );
function vanbodevelops_filter_acc_parameters( $parameters, $order ) {
$transaction_count = get_incremented_transaction_attempt( $order );
// Check if the order is paid and which attempt of transaction it is