#1416
Soft79
Keymaster

Hi Eugeneus,

Yes, you’re right the documentation still has to be written….

In a nutshell:

  • The API functions are in the file WJECF_Pro_API.php, and examples on how to use them are in wjecf-pro-api-example.php
  • If you would like to build your own extra functionality for this plugin, hook into the wjecf_init_plugins-action. Then create a class that extends Abstract_WJECF_Plugin and load it by calling WJECF()->add_plugin( 'NameOfYourClass');
    • Create a function init_hook(), where you setup your plugin and define frontend hooks.
    • Create a function init_admin_hook(), where you setup your plugin for admin usage and define admin hooks.
    • If you would like to add admin fields, you can use the WooCommerce functions (like woocommerce_wp_text_input) for that, for example by hooking into the woocommerce_coupon_options_usage_restriction action, you can add fields to the Usage Restrictions tab. Or use one of these actions for my plugin: wjecf_coupon_metabox_checkout, wjecf_coupon_metabox_customer, wjecf_coupon_metabox_misc, wjecf_coupon_metabox_free_products.
    • For version 2.5.1+ create a function admin_coupon_meta_fields( $coupon ), and make it return an array [ 'field_name' => 'sanitation', ... ] . Upon saving a coupon, these fields will be automatically read from $_POST and sanitized with the given sanition method, e.g. 'int', 'int[]', 'yesno', 'decimal', 'clean' or even a callback: [ 'callback' => callback ] and saved to the current coupon. For versions prior to 2.5.1, you need to handle process_shop_coupon_meta yourself.
  • These are currently the available filters:
    • apply_filters( 'wjecf_bogo_product_amount_for_coupon', $qty, $coupon )
    • apply_filters( 'wjecf_set_free_product_amount_in_cart', $quantity, $product )
    • apply_filters( 'wjecf_free_product_amount_for_coupon', $coupon_qty, $coupon )
    • apply_filters( 'wjecf_free_cart_item_price', __('Free!', 'woocommerce'), $price_html, $cart_item, $cart_item_key )
    • apply_filters( 'wjecf_free_cart_item_subtotal', __('Free!', 'woocommerce'), $price_html, $cart_item, $cart_item_key )
    • apply_filters( 'wjecf_coupon_can_be_applied', $can_be_applied, $coupon )
    • apply_filters( 'wjecf_coupon_has_a_value', $has_a_value, $coupon )

If you have any questions, just let me know.