Git Product home page Git Product logo

optional-force-sells's Introduction

Optional Force Sells

This plugin adds an 'Optional Force Sells' checkbox in the 'Linked Products' tab of the Edit Product screen. When checked, the product's Single Product page will offer each force sell (normal and synced) as a checkbox instead of listing the products which will be added to the cart.

This plugin requires WooCommerce Force Sells to function.

Installation

To install, download optional-force-sells.zip, and upload it in the WP Admin โ†’ Plugins area of your WordPress site.

How it works

Since there is no filter in Force Sells to select which product IDs are added, the plugin saves the list of selected force sells on the cart item, then checks each force sell's ID against the selections. If the force sell ID is not in the list when the product is added to the cart:

  • The id key for the force sell is set to null using the wc_force_sell_add_to_cart_product filter. This makes the add to cart attempt fail.
  • Filter wc_force_sell_disallow_no_stock to false, since otherwise Force Sells will not add the main item (or any items) to the cart if a force sell product wasn't added successfully.

Limitations:

  • This only affects the Single Product page. Adding to the cart elsewhere adds all the force sell items to the cart (the default Force Sells behavior).
  • There is no notice if the add-on can't be forced into the cart, and the initial list of force sells is not filtered by availability. Force sells which are selected but aren't available will silently fail to be added to the cart.
  • This plugin does not distinguish between synced and unsynced force sells or let you choose which force sells to make optional; it is all or nothing for each product.
  • To avoid name collision, this plugin uses the ofs_ function prefix. The likelihood of collision remains low - but it is higher than another method such as a singleton.
  • Some code is copied directly from Force Sells due to being inaccessible at runtime, so the plugin is fragile to implementation changes in Force Sells. That said, Force Sells has had stable data structures for quite some time that probably won't change anytime soon. The copied bits in the code aere noted for easy updating if needed.

optional-force-sells's People

Contributors

melek avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.