Skip to content

Instantly share code, notes, and snippets.

@InpsydeNiklas
InpsydeNiklas / functions.php
Last active July 22, 2022 19:04
Disable PayPal Payments basic Checkout validation in version 1.9.0+
<?php
add_filter('woocommerce_paypal_payments_basic_checkout_validation_enabled', function($enabled) {
return false;
});
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active July 22, 2022 19:02
disable PayPal Payments (incl. PayPal Card Processing) for subscription type products with Vaulting enabled (mini cart button may still render)
<?php
// removes PayPal smart buttons on single product page for subscription type products
function ppcp_remove_single_product_buttons( $enable_button, $product ){
if ( $product->is_type( 'subscription' ) ) {
$enable_button = false;
}
return $enable_button;
}
add_action( 'woocommerce_paypal_payments_product_supports_payment_request_button', 'ppcp_remove_single_product_buttons', 10, 2 );
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active August 19, 2022 14:56
Exclude PayPal Payments scripts from JavaScript Minification (Frontend Optimization) in the SiteGround Optimizer plugin. Only relevant on SiteGround-hosted websites on PayPal Payments v1.9.2.
<?php
add_filter(
'sgo_js_minify_exclude',
function ( array $scripts ) {
$scripts_to_exclude = array( 'ppcp-smart-button', 'ppcp-oxxo', 'ppcp-pay-upon-invoice', 'ppcp-vaulting-myaccount-payments', 'ppcp-gateway-settings', 'ppcp-webhooks-status-page', 'ppcp-tracking' );
return array_merge( $scripts, $scripts_to_exclude );
}
);
@InpsydeNiklas
InpsydeNiklas / functions.php
Created August 24, 2022 22:48
disable PayPal Payments smart buttons on single product page for WooCommerce Bookings product
<?php
// removes PayPal smart buttons on single product page for bookable type products from WooCommerce Bookings plugin
function ppcp_remove_single_product_buttons( $enable_button, $product ){
if ( $product->is_type( 'booking' ) ) {
$enable_button = false;
}
return $enable_button;
}
add_action( 'woocommerce_paypal_payments_product_supports_payment_request_button', 'ppcp_remove_single_product_buttons', 10, 2 );
@InpsydeNiklas
InpsydeNiklas / functions.php
Created October 17, 2022 16:03
disable the Pay upon Invoice gateway for specific product IDs - WooCommerce PayPal Payments
<?php
function remove_ppcp_pui_for_products( $available_gateways ) {
// Not in backend (admin)
if( is_admin() )
return $available_gateways;
// Set var default state
@InpsydeNiklas
InpsydeNiklas / functions.php
Created November 3, 2022 17:42
MultilingualPress - Automatically copy WooCommerce product SKU & Price to all connected products
<?php
add_action('multilingualpress.metabox_after_relate_posts', function($context, $request) {
// get post meta value from source site
$sku = (string)$request->bodyValue(
'_sku',
INPUT_POST,
FILTER_SANITIZE_STRING
);
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active November 25, 2022 14:01
Negative testing PayPal Payments
<?php
add_filter('ppcp_request_args', function ($args, $url){
if (strpos($url,'capture') !== false) {
$args['headers']['PayPal-Mock-Response'] = '{"mock_application_codes": "INSTRUMENT_DECLINED"}';
}
return $args;
}, 10, 2);
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active January 27, 2023 16:32
disable PayPal Payments (incl. PayPal Card Processing) for product with a given ID (mini cart button may still render)
<?php
// removes PayPal smart buttons on single product page for a product with a given id
function ppcp_remove_single_product_buttons() {
$product = wc_get_product();
if ($product) {
if ( $product->get_id() == 24 ) {
return false;
}
else { return true;}
@InpsydeNiklas
InpsydeNiklas / functions.php
Created February 1, 2023 10:28
display icon for ppcp-card-button-gateway in the checkout
<?php
function woocommerce_paypal_payments_card_button_gateway_icon( $icon, $id ) {
if ( $id === 'ppcp-card-button-gateway' ) {
return '<img src="https://upload.wikimedia.org/wikipedia/commons/2/2a/Mastercard-logo.svg" alt="Mastercard" /> <img src="https://upload.wikimedia.org/wikipedia/commons/0/04/Visa.svg" alt="Visa" /> <img src="https://www.paypalobjects.com/webstatic/mktg/Logo/pp-logo-100px.png" alt="PayPal Payments" />';
} else {
return $icon;
}
}
add_filter( 'woocommerce_gateway_icon', 'woocommerce_paypal_payments_card_button_gateway_icon', 10, 2 );
@InpsydeNiklas
InpsydeNiklas / functions.php
Created February 3, 2023 18:13
Add "What is PayPal?" text to PayPal Payments gateway title
<?php
function add_ppcp_gateway_title_link( $title, $id ) {
if ( 'ppcp-gateway' === $id ) {
$title .= sprintf( ' <a href="%s" class="about_ppcp" onclick="javascript:window.open(\'%s\',\'WIPPcp\',\'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=1060, height=700\'); return false;" title="What is PayPal?">What is PayPal?</a>', esc_url( 'https://www.paypal.com/us/webapps/mpp/paypal-popup' ), esc_url( 'https://www.paypal.com/us/webapps/mpp/paypal-popup' ) );
}
return $title;
}
add_filter( 'woocommerce_gateway_title', 'add_ppcp_gateway_title_link', 10, 2 );