Partial.ly
Back to home

WooCommerce Plugin Advanced Customizations

WooCommerce Plugin Advanced Customizations

The WooCommerce plugin offers various hooks and filters to customize its behavior. To override the functionality, add code to your theme's functions.php file.

Filters

  • partially_gateway_offer (string) — the offer ID to use when creating a payment plan for gateway checkout
  • partially_widget_config (array) — PHP array of options for the partially-widget
  • partially_widget_container_html (string) — raw HTML to use as the container for the widget
  • partially_button_cart_offer (string) — the offer ID to use when creating a checkout button on the cart page
  • partially_button_cart_config (array) — PHP array of options for the checkout button on the cart page
  • partially_button_product_offer (string) — offer ID to use when creating a checkout button on the product landing page
  • partially_button_product_config (array) — PHP array of options for the checkout button on the product page
  • partially_button_product_container_html (string) — HTML to use as the container for the checkout button on the product page

Examples

The following are a few examples of common scenarios, which you can add to your theme's functions.php file.

Change Offer Based on Order Total

The following example shows how you might change the offer used during checkout if the cart total is over $500. You may want different terms depending on the order amount, using different offers. Be sure to update the value and offer IDs to match your needs.

function custom_partially_gateway_offer($default_offer) {
    if ( WC()->cart->total > 500) {
        return '<custom offer ID>';
    }
    else return $default_offer;
}
add_filter('partially_gateway_offer', 'custom_partially_gateway_offer');

Enable Widget Based on Product Tag

Perhaps you only want the Partially widget to display on product pages tagged with partially-widget. The following code causes the widget to only display on product pages with that tag.

function custom_partially_widget_settings($settings) {
    $settings['render'] = false;
    $tags = get_the_terms( get_the_ID(), 'product_tag' );
    if ($tags) {
        foreach ($tags as $tag) {
            if ($tag->name == 'partially-widget') $settings['render'] = true;
        }
    }
    return $settings;
}
add_filter('partially_widget_config', 'custom_partially_widget_settings');

Disable the Partially Payment Method at Checkout

If you only want the Partially payment gateway available at checkout for carts over a certain amount, use the following in your theme's functions.php file.

// remove Partially option for carts below $100
function maybe_remove_partially($gateways) {
    if (WC()->cart->total < 100) unset($gateways['partially']);
    return $gateways;
}
add_filter('woocommerce_available_payment_gateways', 'maybe_remove_partially');