Skip to content

Instantly share code, notes, and snippets.

View vanbo's full-sized avatar

Ivan Andreev vanbo

View GitHub Profile
@vanbo
vanbo / stripe-charge
Last active June 9, 2016 13:52
Charge
<?php
\Stripe\Stripe::setApiKey('the_key');
// I do set this usually, but tried without it, too
\Stripe\Stripe::setApiVersion('2016-03-07');
$card = array(
'number' => '4242424242424242',
'exp_month' => 5,
@vanbo
vanbo / linnworks-change-discount-item-sku
Created June 16, 2016 13:06
Linnworks Discount Item SKU
add_filter( 'wc_linnworks_orders_discount_sku_name', 'linnworks_change_discount_item_sku' );
function linnworks_change_discount_item_sku($sku) {
// Change the SKU value by returning a new value
return 'NEW-SKU-HERE';
}
@vanbo
vanbo / borica-encryption-password-filter
Created June 30, 2016 09:23
Borica encryption password filter
add_filter( 'wc_borica_certificates_password', 'prefix_add_filter' );
function prefix_add_filter( $name ) {
return 'your-password-here';
}
@vanbo
vanbo / remove-bacs-from-wc-thank-you-page
Created October 12, 2016 09:12
Remove BACS details from WooCommerce Thank You page
add_action( 'init', 'remove_bacs_from_thank_you_page', 100 );
function remove_bacs_from_thank_you_page() {
// Bail, if we don't have WC function
if ( ! function_exists( 'WC' ) ) {
return;
}
// Get all available gateways
$available_gateways = WC()->payment_gateways()->get_available_payment_gateways();
@vanbo
vanbo / woocommerce-psigate-multi-currency-setup
Last active July 30, 2020 21:23
WooCommerce Psigate multi-currency setup
/**
* The code goes into your "theme\functions.php" file or any php file that is loaded on page load.
*/
// AM API Process Payment
add_filter( 'wc_psigate_process_acc_manager_payment_parameters', 'psigate_modify_account_manager_api_credentials_on_currency', 10, 2 );
// AM API Register Customer Account
add_filter( 'wc_psigate_register_customer_account_parameters', 'psigate_modify_account_manager_api_credentials_on_currency', 10, 2 );
/**
* Modifies the Account Manager API credentials, based on currency code
@vanbo
vanbo / restrict-users-to-their-own-attachments
Created May 11, 2017 09:09
WordPress Media Uploader: Restrict User to Accessing Only Files They Uploaded
add_filter( 'ajax_query_attachments_args', 'filter_query_attachments_args' );
function filter_query_attachments_args( $query ) {
// 1. Only users with access
if ( ! current_user_can( 'upload_files' ) ) {
wp_send_json_error();
}
// 2. No manipulation for admins.
// After all they have access to all images.
@vanbo
vanbo / psigate-curl-ssl-version.php
Created June 21, 2017 09:32
psigate-curl-ssl-version
if ( ! function_exists( 'your_site_curl_ssl_v3' ) ) {
add_action( 'http_api_curl', 'your_site_curl_ssl_v3' );
function your_site_curl_ssl_v3( $handle ) {
curl_setopt($handle, CURLOPT_SSLVERSION, 1);
}
}
@vanbo
vanbo / wc-filter-cart-contents-weight
Created October 24, 2017 09:51
Filter WooCommerce Cart Contents Weight
add_filter( 'woocommerce_cart_contents_weight', 'prefix_filter_cart_contents_weight' );
function prefix_filter_cart_contents_weight( $weight ) {
/**
* Adding 170 units to the total cart weight.
*/
return $weight + 170;
}
@vanbo
vanbo / wc-add-product-to-cart-based-on-another-product
Last active October 30, 2017 11:55
Add a product and quantity to cart, based on another product and quantity.
add_action( 'woocommerce_add_to_cart', 'prefix_add_additional_product', 10, 6 );
/**
* Adds additional product to cart based on the quantity of an added product
*/
function prefix_add_additional_product( $cart_item_key, $product_id, $quantity, $variation_id, $variation, $cart_item_data ) {
// Get the cart
$cart = WC()->cart->get_cart();
// Nothing, if the cart is empty
if ( 0 == count( $cart ) ) {
@vanbo
vanbo / woocommerce-save-custom-checkout-field
Created October 26, 2017 14:19
WooCommerce: Save custom checkout field
add_action( 'woocommerce_checkout_order_processed', 'prefix_save_field_on_checkout', 11, 2 );
function checkout_order_processed_add_referral_answer( $order_id, $posted ) {
if ( ! isset( $_POST['checkout_field_name'] ) ) {
return;
}
$order = wc_get_order( $order_id );
// WC < 3.0
update_post_meta( $order->id, 'order_meta_field_name', wc_clean( $_POST['checkout_field_name'] ) );