Skip to content

Instantly share code, notes, and snippets.

@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
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
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 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
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
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 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
Created March 25, 2022 01:38
Remove undismissable WooThemes Updater notification: Install/Activate the WooThemes Helper plugin to get updates for your WooThemes plugins.
add_action( 'init', 'remove_woothemes_updater_notice' );
/**
* Remove the undismissable admin notice to install/activate the WooThemes Helper plugin.
*/
function remove_woothemes_updater_notice() {
remove_action( 'admin_notices', 'woothemes_updater_notice' );
}
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active November 3, 2022 17:56
MultilingualPress - Copy SKU & Price to Product Data tab in the metabox for the remote product(s)
<?php
use Inpsyde\MultilingualPress\TranslationUi\Post\RelationshipContext;
add_action('multilingualpress.metabox_after_update_remote_product',
static function(RelationshipContext $context, WC_Product $remoteProduct, WC_Product $sourceProduct) {
$remoteSku = $remoteProduct->get_sku() ?? '';
$remotePrice = $remoteProduct->get_price() ?? '';
if (!empty($remoteSku) && !empty($remotePrice)) {
return;
@InpsydeNiklas
InpsydeNiklas / functions.php
Last active July 22, 2022 19:05
MultilingualPress copy post meta GTIN field from Product Feed PRO ELITE
<?php
add_action('multilingualpress.metabox_after_relate_posts', function($context, $request) {
// get post meta value from source site
$ProductFeedELITEGtinValue = (string)$request->bodyValue(
'_woosea_gtin',
INPUT_POST,
FILTER_SANITIZE_STRING
);