<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Extending - CODIBU</title>
	<atom:link href="https://help.codibu.com/kbtopic/extending/feed/" rel="self" type="application/rss+xml" />
	<link>https://help.codibu.com</link>
	<description>Hosting &#38; Domain,  Development &#38; Design, SEO &#38; Marketing, 2300+ Themes &#38; Plugins, Free SEO analysis &#38; tools</description>
	<lastBuildDate>Sun, 08 Nov 2020 16:04:56 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://help.codibu.com/wp-content/uploads/2022/07/favicon.png</url>
	<title>Extending - CODIBU</title>
	<link>https://help.codibu.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Developing using WooCommerce CRUD objects</title>
		<link>https://help.codibu.com/blog/developing-using-woocommerce-crud-objects/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=developing-using-woocommerce-crud-objects</link>
					<comments>https://help.codibu.com/blog/developing-using-woocommerce-crud-objects/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:04:56 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/developing-using-woocommerce-crud-objects/</guid>

					<description><![CDATA[<p>CRUD is an abbreviation of the 4 basic operations you can do to a database or resource – Create, Read, Update, Delete. WooCommerce 3.0 introduced CRUD<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/developing-using-woocommerce-crud-objects/">Developing using WooCommerce CRUD objects</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>CRUD is an abbreviation of the 4 basic operations you can do to a database or resource – Create, Read, Update, Delete.</p>
<p><a href="https://help.codibu.com/blog/kb/the-new-crud-classes-in-woocommerce-2-7/">WooCommerce 3.0 introduced CRUD objects</a> for working with WooCommerce data. <strong>Whenever possible it is best-practices to use these objects in your code instead of directly updating metadata or using WordPress post objects.</strong> The following objects are handled by CRUD objects and data-stores:</p>
<ul>
<li>Orders</li>
<li>Order line items</li>
<li>Products</li>
<li>Coupons</li>
<li>Customers</li>
<li>Customer downloads</li>
<li>Payment tokens</li>
<li>Shipping zones</li>
<li>Webhooks</li>
</ul>
<p>Each of these objects contains a schema for the data it controls (properties), a getter and setter for each property, and a save/delete method which talks to a <strong>data store</strong>.</p>
<p>The data store handles the actual saving/reading from the database – the object itself does not need to be aware of where the data is stored. You can read about data stores here.</p>
<h2 id="section-1">The benefits of CRUD</h2>
<ul>
<li>Structure – each object has a pre-defined structure and keeps it’s own data valid.</li>
<li>Control – We control the flow of data, and any validation needed, so we know when changes occur.</li>
<li>Ease of development – As a developer, you don’t need to know the internals of the data you’re working with, just the names.</li>
<li>Abstraction – The data can be moved elsewhere e.g. custom tables, without affecting existing code.</li>
<li>Unification – We can use the same code for updating things in admin as we do in the REST API and CLIs – everything is unified.</li>
<li>Simplified code – less procedural code to update objects which reduces likelihood of malfunction and adds more unit test coverage.</li>
</ul>
<h2 id="section-2">CRUD object structure</h2>
<p>The <code>WC_Data</code> class is the basic implementation for CRUD objects, and all CRUD objects extend it.</p>
<p>The most important parts to note: <code>$data</code> is an array of props supported in each object, and <code>$id</code> is the object’s ID.</p>
<p>The coupon object class is a good example of extending WC_Data and adding CRUD functions to all properties.</p>
<h3 id="section-3">Data</h3>
<p><code>$data</code> stores the property names, and default values:</p>
<pre><code>        /**
     * Data array, with defaults.
     * @since 3.0.0
     * @var array
     */
    protected $data = array(
        'code'                        =&gt; '',
        'amount'                      =&gt; 0,
        'date_created'                =&gt; '',
        'date_modified'               =&gt; '',
        'discount_type'               =&gt; 'fixed_cart',
        'description'                 =&gt; '',
        'date_expires'                =&gt; '',
        'usage_count'                 =&gt; 0,
        'individual_use'              =&gt; false,
        'product_ids'                 =&gt; array(),
        'excluded_product_ids'        =&gt; array(),
        'usage_limit'                 =&gt; 0,
        'usage_limit_per_user'        =&gt; 0,
        'limit_usage_to_x_items'      =&gt; 0,
        'free_shipping'               =&gt; false,
        'product_categories'          =&gt; array(),
        'excluded_product_categories' =&gt; array(),
        'exclude_sale_items'          =&gt; false,
        'minimum_amount'              =&gt; '',
        'maximum_amount'              =&gt; '',
        'email_restrictions'          =&gt; array(),
        'used_by'                     =&gt; array(),
    );
</code></pre>
<h3 id="section-4">Getters and setters</h3>
<p>Each one of the keys in this array (property) has a getter and setter, e.g. <code>set_used_by()</code> and <code>get_used_by()</code>. <code>$data</code> itself is private, so the getters and setters <strong>must</strong> be used to access the data.</p>
<p>Example getter:</p>
<pre><code>
    /**
     * Get records of all users who have used the current coupon.
     * @since  3.0.0
     * @param  string $context
     * @return array
     */
    public function get_used_by( $context = 'view' ) {
        return $this-&gt;get_prop( 'used_by', $context );
    }
</code></pre>
<p>Example setter:</p>
<pre><code>    /**
     * Set which users have used this coupon.
     * @since 3.0.0
     * @param array $used_by
     * @throws WC_Data_Exception
     */
    public function set_used_by( $used_by ) {
        $this-&gt;set_prop( 'used_by', array_filter( $used_by ) );
    }
</code></pre>
<p><code>set_prop</code> and <code>get_prop</code> are part of <code>WC_Data</code>. These apply various filters (based on context) and handle changes (so we can save only changes and not all props).</p>
<p>A note on <code>$context</code>: when getting data to use on the frontend or display, <code>view</code> context is used. This applies filters to the data so extensions can change the values dynamically.</p>
<p><code>edit</code> context should be used when showing values to edit in the backend, and for saving to the database. Using <code>edit</code> context does not apply any filters to the data.</p>
<h3 id="section-5">The constructor</h3>
<p>The constructor of the CRUD objects facilitates the read from the database. The actual read is not done by the CRUD class, but by its data store.</p>
<p>Example:</p>
<pre><code>    /**
     * Coupon constructor. Loads coupon data.
     * @param mixed $data Coupon data, object, ID or code.
     */
    public function __construct( $data = '' ) {
        parent::__construct( $data );

        if ( $data instanceof WC_Coupon ) {
            $this-&gt;set_id( absint( $data-&gt;get_id() ) );
        } elseif ( is_numeric( $data ) &amp;&amp; 'shop_coupon' === get_post_type( $data ) ) {
            $this-&gt;set_id( $data );
        } elseif ( ! empty( $data ) ) {
            $this-&gt;set_id( wc_get_coupon_id_by_code( $data ) );
            $this-&gt;set_code( $data );
        } else {
            $this-&gt;set_object_read( true );
        }

        $this-&gt;data_store = WC_Data_Store::load( 'coupon' );
        if ( $this-&gt;get_id() &gt; 0 ) {
            $this-&gt;data_store-&gt;read( $this );
        }
    }
</code></pre>
<p>Note how it sets the ID based on the data passed to the object, then calls the data store to retrieve the data from the database.</p>
<p>Once the data is read via the data store, or if no ID is set, <code>$this-&gt;set_object_read( true );</code> is set so the data store and CRUD object knows it’s read. Once this is set, changes are tracked.</p>
<h3 id="section-6">Saving and deleting</h3>
<p>Save and delete methods are optional at CRUD object level because the <code>WC_Data</code> class can handle it. When <code>save</code> is called, the data store is used to store data to the database. Delete removes the object from the database. <code>save</code> must be called for changes to persist, otherwise they will be discarded.</p>
<p>The save method looks like this in <code>WC_Data</code>:</p>
<pre><code>    /**
     * Save should create or update based on object existence.
     *
     * @since  2.6.0
     * @return int
     */
    public function save() {
        if ( $this-&gt;data_store ) {
            // Trigger action before saving to the DB. Allows you to adjust object props before save.
            do_action( 'woocommerce_before_' . $this-&gt;object_type . '_object_save', $this, $this-&gt;data_store );

            if ( $this-&gt;get_id() ) {
                $this-&gt;data_store-&gt;update( $this );
            } else {
                $this-&gt;data_store-&gt;create( $this );
            }
            return $this-&gt;get_id();
        }
    }
</code></pre>
<p>Update/create is used depending on whether the object has an ID yet. The ID will be set after creation.</p>
<p>The delete method is like this:</p>
<pre><code>    /**
     * Delete an object, set the ID to 0, and return result.
     *
     * @since  2.6.0
     * @param  bool $force_delete
     * @return bool result
     */
    public function delete( $force_delete = false ) {
        if ( $this-&gt;data_store ) {
            $this-&gt;data_store-&gt;delete( $this, array( 'force_delete' =&gt; $force_delete ) );
            $this-&gt;set_id( 0 );
            return true;
        }
        return false;
    }
</code></pre>
<h2 id="section-7">CRUD Usage Examples</h2>
<h3 id="section-8">Creating a new simple product</h3>
<pre><code>$product = new WC_Product_Simple();
$product-&gt;set_name( 'My Product' );
$product-&gt;set_slug( 'myproduct' );
$product-&gt;set_description( 'A new simple product' );
$product-&gt;set_regular_price( '9.50' );
$product-&gt;save();

$product_id = $product-&gt;get_id();
</code></pre>
<h3 id="section-9">Updating an existing coupon</h3>
<pre><code>$coupon = new WC_Coupon( $coupon_id );
$coupon-&gt;set_discount_type( 'percent' );
$coupon-&gt;set_amount( 25.00 );
$coupon-&gt;save();
</code></pre>
<h3 id="section-10">Retrieving a customer</h3>
<pre><code>$customer = new WC_Customer( $user_id );
$email    = $customer-&gt;get_email();
$address  = $customer-&gt;get_billing_address();
$name     = $customer-&gt;get_first_name() . ' ' . $customer-&gt;get_last_name();</code></pre><p>The post <a href="https://help.codibu.com/blog/developing-using-woocommerce-crud-objects/">Developing using WooCommerce CRUD objects</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/developing-using-woocommerce-crud-objects/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Adding a Section to a Settings Tab</title>
		<link>https://help.codibu.com/blog/adding-a-section-to-a-settings-tab/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=adding-a-section-to-a-settings-tab</link>
					<comments>https://help.codibu.com/blog/adding-a-section-to-a-settings-tab/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:04:26 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/adding-a-section-to-a-settings-tab/</guid>

					<description><![CDATA[<p>When you’re adding building an extension for WooCommerce that requires settings of some kind, it’s important to ask yourself: Where do they belong? If your extension just<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/adding-a-section-to-a-settings-tab/">Adding a Section to a Settings Tab</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>When you’re adding building an extension for WooCommerce that requires settings of some kind, it’s important to ask yourself: <strong>Where do they belong?</strong></p>
<p>If your extension just has a couple of simple settings, do you really need to create a new tab specifically for it? Most likely the answer is no.</p>
<h2 id="section-1">When to Create a Section</h2>
<p>Let’s say we had an extension that adds a slider to a single product page. This extension doesn’t have many options, just a couple:</p>
<ul>
<li>Auto-insert into single product page (checkbox)</li>
<li>Slider Title (text field)</li>
</ul>
<p>That’s only two options, specifically related to <strong>Products</strong>. We could quite easily just append them onto the core WooCommerce Products Settings (<strong>WooCommerce &gt; Settings &gt; Products</strong>), but that wouldn’t be very user friendly. Users wouldn’t know where to look initially so they’d have to scan all of the Products options and it would be difficult / impossible to link the options directly.</p>
<p>Fortunately, as of WooCommerce 2.2.2, there is a new filter in place that allows you add a new <strong>section</strong>, beneath one of the core settings’ tabs.</p>
<p class="p1"> </p>
<div class="woo-sc-box note   "><b>Note:</b> This is a <b>Developer level</b> doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a <a href="https://woocommerce.com/customizations/"><span class="s2">WooExpert or Developer</span></a> for assistance. We are unable to provide support for customizations under our<span class="Apple-converted-space">  </span><a href="https://help.codibu.com/blog/kb/support-policy/"><span class="s2">Support Policy</span></a>.</div>
<p>&nbsp;</p>
<h2 id="section-2">How to Create a Section</h2>
<p>We’ll go over doing this through individual functions, but you should probably create a Class that stores all of your settings methods.</p>
<p class="p1">The first thing you need to is add the section, which can be done like this by hooking into the <code>woocommerce_get_sections_products</code> filter:</p>
<div id="gist88075741" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-create-section-beneath-products-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-hack  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-create-section-beneath-products-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-create-section-beneath-products-php-LC1" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-create-section-beneath-products-php-LC2" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Create the section beneath the products tab</span></td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-create-section-beneath-products-php-LC3" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> **/</span></td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-create-section-beneath-products-php-LC4" class="blob-code blob-code-inner js-file-line"><span class="pl-en">add_filter</span>( <span class="pl-s"><span class="pl-pds">&#8216;</span>woocommerce_get_sections_products<span class="pl-pds">&#8216;</span></span>, <span class="pl-s"><span class="pl-pds">&#8216;</span>wcslider_add_section<span class="pl-pds">&#8216;</span></span> );</td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-create-section-beneath-products-php-LC5" class="blob-code blob-code-inner js-file-line"><span class="pl-k">function</span> <span class="pl-en">wcslider_add_section</span>( <span class="pl-smi">$sections</span> ) {</td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-create-section-beneath-products-php-LC6" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-create-section-beneath-products-php-LC7" class="blob-code blob-code-inner js-file-line"><span class="pl-smi">$sections</span>[<span class="pl-s"><span class="pl-pds">&#8216;</span>wcslider<span class="pl-pds">&#8216;</span></span>] <span class="pl-k">=</span> <span class="pl-en">__</span>( <span class="pl-s"><span class="pl-pds">&#8216;</span>WC Slider<span class="pl-pds">&#8216;</span></span>, <span class="pl-s"><span class="pl-pds">&#8216;</span>text-domain<span class="pl-pds">&#8216;</span></span> );</td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-create-section-beneath-products-php-LC8" class="blob-code blob-code-inner js-file-line"><span class="pl-k">return</span> <span class="pl-smi">$sections</span>;</td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-create-section-beneath-products-php-LC9" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-section-beneath-products-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-create-section-beneath-products-php-LC10" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>Make sure you change the <strong>wcslider</strong> parts to suit your extension’s name / text-domain.</p>
<p>The important thing about the <code>woocommerce_get_sections_products</code> filter, is that the last part <strong>products</strong>, is the tab you’d like to add a section to. So if you want to add a new tab to accounts section, you would hook into the <code>woocommerce_get_sections_accounts</code> filter.</p>
<h2 id="section-3">How to Add Settings to a Section</h2>
<p>Now that you’ve got the tab, you need to filter the output of <code>woocommerce_get_sections_products</code> (or similar). You would add the settings like usual using the <a href="https://help.codibu.com/blog/kb/settings-api/"><strong>WooCommerce Settings API</strong></a>, but check for the current section before adding the settings to the tab’s settings array.</p>
<p>For example, let’s add the sample settings we discussed above to the new <strong>wcslider</strong> section we just created:</p>
<div id="gist88075776" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-add-settings-section-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-add-settings-section-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-add-settings-section-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-add-settings-section-php-LC2" class="blob-code blob-code-inner js-file-line">* Add settings to the specific section we created before</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-add-settings-section-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-add-settings-section-php-LC4" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_get_settings_products&#8217;, &#8216;wcslider_all_settings&#8217;, 10, 2 );</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-add-settings-section-php-LC5" class="blob-code blob-code-inner js-file-line">function wcslider_all_settings( $settings, $current_section ) {</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-add-settings-section-php-LC6" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-add-settings-section-php-LC7" class="blob-code blob-code-inner js-file-line">* Check the current section is what we want</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-add-settings-section-php-LC8" class="blob-code blob-code-inner js-file-line">**/</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-add-settings-section-php-LC9" class="blob-code blob-code-inner js-file-line">if ( $current_section == &#8216;wcslider&#8217; ) {</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-add-settings-section-php-LC10" class="blob-code blob-code-inner js-file-line">$settings_slider = array();</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-add-settings-section-php-LC11" class="blob-code blob-code-inner js-file-line">// Add Title to the Settings</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-add-settings-section-php-LC12" class="blob-code blob-code-inner js-file-line">$settings_slider[] = array( &#8216;name&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;WC Slider Settings&#8217;, &#8216;text-domain&#8217; ), &#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;title&#8217;, &#8216;desc&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;The following options are used to configure WC Slider&#8217;, &#8216;text-domain&#8217; ), &#8216;id&#8217; =<span class="pl-kos">&gt;</span> &#8216;wcslider&#8217; );</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-add-settings-section-php-LC13" class="blob-code blob-code-inner js-file-line">// Add first checkbox option</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-add-settings-section-php-LC14" class="blob-code blob-code-inner js-file-line">$settings_slider[] = array(</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-add-settings-section-php-LC15" class="blob-code blob-code-inner js-file-line">&#8216;name&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Auto-insert into single product page&#8217;, &#8216;text-domain&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-add-settings-section-php-LC16" class="blob-code blob-code-inner js-file-line">&#8216;desc_tip&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;This will automatically insert your slider into the single product page&#8217;, &#8216;text-domain&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-add-settings-section-php-LC17" class="blob-code blob-code-inner js-file-line">&#8216;id&#8217; =<span class="pl-kos">&gt;</span> &#8216;wcslider_auto_insert&#8217;,</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-add-settings-section-php-LC18" class="blob-code blob-code-inner js-file-line">&#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;checkbox&#8217;,</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-wc-add-settings-section-php-LC19" class="blob-code blob-code-inner js-file-line">&#8216;css&#8217; =<span class="pl-kos">&gt;</span> &#8216;min-width:300px;&#8217;,</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-wc-add-settings-section-php-LC20" class="blob-code blob-code-inner js-file-line">&#8216;desc&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Enable Auto-Insert&#8217;, &#8216;text-domain&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-wc-add-settings-section-php-LC21" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-wc-add-settings-section-php-LC22" class="blob-code blob-code-inner js-file-line">// Add second text field option</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-wc-add-settings-section-php-LC23" class="blob-code blob-code-inner js-file-line">$settings_slider[] = array(</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L24" class="blob-num js-line-number" data-line-number="24"> </td>
<td id="file-wc-add-settings-section-php-LC24" class="blob-code blob-code-inner js-file-line">&#8216;name&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Slider Title&#8217;, &#8216;text-domain&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L25" class="blob-num js-line-number" data-line-number="25"> </td>
<td id="file-wc-add-settings-section-php-LC25" class="blob-code blob-code-inner js-file-line">&#8216;desc_tip&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;This will add a title to your slider&#8217;, &#8216;text-domain&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L26" class="blob-num js-line-number" data-line-number="26"> </td>
<td id="file-wc-add-settings-section-php-LC26" class="blob-code blob-code-inner js-file-line">&#8216;id&#8217; =<span class="pl-kos">&gt;</span> &#8216;wcslider_title&#8217;,</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L27" class="blob-num js-line-number" data-line-number="27"> </td>
<td id="file-wc-add-settings-section-php-LC27" class="blob-code blob-code-inner js-file-line">&#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;text&#8217;,</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L28" class="blob-num js-line-number" data-line-number="28"> </td>
<td id="file-wc-add-settings-section-php-LC28" class="blob-code blob-code-inner js-file-line">&#8216;desc&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Any title you want can be added to your slider with this option!&#8217;, &#8216;text-domain&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L29" class="blob-num js-line-number" data-line-number="29"> </td>
<td id="file-wc-add-settings-section-php-LC29" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L30" class="blob-num js-line-number" data-line-number="30"> </td>
<td id="file-wc-add-settings-section-php-LC30" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L31" class="blob-num js-line-number" data-line-number="31"> </td>
<td id="file-wc-add-settings-section-php-LC31" class="blob-code blob-code-inner js-file-line">$settings_slider[] = array( &#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;sectionend&#8217;, &#8216;id&#8217; =<span class="pl-kos">&gt;</span> &#8216;wcslider&#8217; );</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L32" class="blob-num js-line-number" data-line-number="32"> </td>
<td id="file-wc-add-settings-section-php-LC32" class="blob-code blob-code-inner js-file-line">return $settings_slider;</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L33" class="blob-num js-line-number" data-line-number="33"> </td>
<td id="file-wc-add-settings-section-php-LC33" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L34" class="blob-num js-line-number" data-line-number="34"> </td>
<td id="file-wc-add-settings-section-php-LC34" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L35" class="blob-num js-line-number" data-line-number="35"> </td>
<td id="file-wc-add-settings-section-php-LC35" class="blob-code blob-code-inner js-file-line">* If not, return the standard settings</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L36" class="blob-num js-line-number" data-line-number="36"> </td>
<td id="file-wc-add-settings-section-php-LC36" class="blob-code blob-code-inner js-file-line">**/</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L37" class="blob-num js-line-number" data-line-number="37"> </td>
<td id="file-wc-add-settings-section-php-LC37" class="blob-code blob-code-inner js-file-line">} else {</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L38" class="blob-num js-line-number" data-line-number="38"> </td>
<td id="file-wc-add-settings-section-php-LC38" class="blob-code blob-code-inner js-file-line">return $settings;</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L39" class="blob-num js-line-number" data-line-number="39"> </td>
<td id="file-wc-add-settings-section-php-LC39" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-add-settings-section-php-L40" class="blob-num js-line-number" data-line-number="40"> </td>
<td id="file-wc-add-settings-section-php-LC40" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="gist-meta"> </div>
<p>&nbsp;</p>
</div>
</div>
<p>We’re hooking into the same <code>woocommerce_get_sections_products</code> filter, but this time doing a check that the <code>$current_section</code> matches our earlier defined custom section (wcslider), before adding in our new settings.</p>
<h2 id="section-4">Using the New Settings</h2>
<p>You would now just use your newly created settings like you would any other WordPress / WooCommerce setting, through the <strong>get_option</strong> function and the defined ID of the setting.</p>
<p>For example, to use the previously created <strong>wcslider_auto_insert</strong> option, simply use the following code:</p>
<p><code>get_option( 'wcslider_auto_insert' )</code></p>
<h2 id="section-5">Conclusion</h2>
<p>When creating an extension for WooCommerce, think about where your settings belong before you create them. The key to building a useful product is making it easy to use for the end user, so appropriate setting placement is crucially important.</p>
<p>For more specific information on adding settings to WooCommerce, check out the <a href="https://help.codibu.com/blog/kb/settings-api/"><strong>Settings API documentation</strong></a>.</p><p>The post <a href="https://help.codibu.com/blog/adding-a-section-to-a-settings-tab/">Adding a Section to a Settings Tab</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/adding-a-section-to-a-settings-tab/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Implementing the WC Integration Class</title>
		<link>https://help.codibu.com/blog/implementing-the-wc-integration-class/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-the-wc-integration-class</link>
					<comments>https://help.codibu.com/blog/implementing-the-wc-integration-class/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:03:36 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/implementing-the-wc-integration-class/</guid>

					<description><![CDATA[<p>If you’re customizing WooCommerce or adding your own functionality to it you’ll probably need a settings page of some sort. One of the easiest ways to<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/implementing-the-wc-integration-class/">Implementing the WC Integration Class</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>If you’re customizing WooCommerce or adding your own functionality to it you’ll probably need a settings page of some sort. One of the easiest ways to create a settings page is by taking advantage of the <a title="WC_Integration Class" href="http://docs.woocommerce.com/wc-apidocs/class-WC_Integration.html"><code>WC_Integration</code> class</a>. Using the Integration class will automatically create a new settings page under <strong>WooCommerce &gt; Settings &gt; Integrations</strong> and it will automatically save, and sanitize your data for you.</p>
<p>We’ve created this tutorial so you can see how to create a new integration.</p>
<p class="p1"> </p>
<div class="woo-sc-box note   "><b>Note:</b> This is a <b>Developer level</b> doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a <a href="https://woocommerce.com/customizations/"><span class="s2">WooExpert or Developer</span></a> for assistance. We are unable to provide support for customizations under our<span class="Apple-converted-space">  </span><a href="https://help.codibu.com/blog/kb/support-policy/"><span class="s2">Support Policy</span></a>.</div>
<p>&nbsp;</p>
<h2 id="section-1" class="p1">Setting up the Integration</h2>
<p>You’ll need at least two files to create an integration so you’ll need to create a directory.</p>
<h3 id="section-2">Creating the Main Plugin File</h3>
<p>Create your main plugin file to hook into the <code>plugins_loaded</code> hook and check if the <code>WC_Integration</code> class exists. If it doesn’t then the user most likely doesn’t have WooCommerce activated.</p>
<p>After you do that you need to register the integration. Load the integration file (we’ll get to this file in a minute). Use the <code>woocommerce_integrations</code> filter to add a new integration to the array.</p>
<h3 id="section-3">Creating the Integration Class</h3>
<p>Now that we have the framework setup let’s actually implement this Integration class. There already is a <code>WC_Integration</code> class so we want to make a child class. This way it inherits all of the existing methods and data.</p>
<p>You’ll need to set an id, a description, and a title for your integration. These will show up on the integration page.</p>
<p>You’ll also need to load the settings by calling:<br />
<code>$this-&gt;init_form_fields();</code> &amp; <code>$this-&gt;init_settings();</code></p>
<p>You’ll also need to save your options by calling the <code>woocommerce_update_options_integration_{your method id}</code> hook.</p>
<p>Lastly you have to input some settings to save! I’ve included two dummy fields below but we’ll go more into fields in the next section.</p>
<div id="gist88075234" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-class-wc-integration-demo-integration-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC1" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC2" class="blob-code blob-code-inner js-file-line"><span class="pl-ent">&lt;?php</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC3" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC4" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Integration Demo Integration.</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC5" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> *</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC6" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * @package WC_Integration_Demo_Integration</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC7" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * @category Integration</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC8" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * @author Patrick Rauland</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC9" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC10" class="blob-code blob-code-inner js-file-line"><span class="pl-k">if</span> ( ! <span class="pl-en">class_exists</span>( <span class="pl-s">&#8216;WC_Integration_Demo_Integration&#8217;</span> ) ) :</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC11" class="blob-code blob-code-inner js-file-line"><span class="pl-k">class</span> <span class="pl-v">WC_Integration_Demo_Integration</span> <span class="pl-k">extends</span> <span class="pl-v">WC_Integration</span> {</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC12" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC13" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Init and hook in the integration.</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC14" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC15" class="blob-code blob-code-inner js-file-line"><span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">__construct</span>() {</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC16" class="blob-code blob-code-inner js-file-line"><span class="pl-k">global</span> <span class="pl-s1"><span class="pl-c1">$</span>woocommerce</span>;</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC17" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">id</span> = <span class="pl-s">&#8216;integration-demo&#8217;</span>;</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC18" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">method_title</span> = <span class="pl-en">__</span>( <span class="pl-s">&#8216;Integration Demo&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> );</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC19" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">method_description</span> = <span class="pl-en">__</span>( <span class="pl-s">&#8216;An integration demo to show you how easy it is to extend WooCommerce.&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> );</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC20" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// Load the settings.</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC21" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">init_form_fields</span>();</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC22" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">init_settings</span>();</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC23" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// Define user set variables.</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L24" class="blob-num js-line-number" data-line-number="24"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC24" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">api_key</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get_option</span>( <span class="pl-s">&#8216;api_key&#8217;</span> );</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L25" class="blob-num js-line-number" data-line-number="25"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC25" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">debug</span> = <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get_option</span>( <span class="pl-s">&#8216;debug&#8217;</span> );</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L26" class="blob-num js-line-number" data-line-number="26"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC26" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// Actions.</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L27" class="blob-num js-line-number" data-line-number="27"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC27" class="blob-code blob-code-inner js-file-line"><span class="pl-en">add_action</span>( <span class="pl-s">&#8216;woocommerce_update_options_integration_&#8217;</span> . <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">id</span>, <span class="pl-en">array</span>( <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>, <span class="pl-s">&#8216;process_admin_options&#8217;</span> ) );</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L28" class="blob-num js-line-number" data-line-number="28"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC28" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L29" class="blob-num js-line-number" data-line-number="29"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC29" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L30" class="blob-num js-line-number" data-line-number="30"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC30" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Initialize integration settings form fields.</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L31" class="blob-num js-line-number" data-line-number="31"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC31" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L32" class="blob-num js-line-number" data-line-number="32"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC32" class="blob-code blob-code-inner js-file-line"><span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">init_form_fields</span>() {</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L33" class="blob-num js-line-number" data-line-number="33"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC33" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-c1">form_fields</span> = <span class="pl-en">array</span>(</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L34" class="blob-num js-line-number" data-line-number="34"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC34" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;api_key&#8217;</span> =&gt; <span class="pl-en">array</span>(</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L35" class="blob-num js-line-number" data-line-number="35"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC35" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;title&#8217;</span> =&gt; <span class="pl-en">__</span>( <span class="pl-s">&#8216;API Key&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> ),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L36" class="blob-num js-line-number" data-line-number="36"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC36" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;type&#8217;</span> =&gt; <span class="pl-s">&#8216;text&#8217;</span>,</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L37" class="blob-num js-line-number" data-line-number="37"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC37" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;description&#8217;</span> =&gt; <span class="pl-en">__</span>( <span class="pl-s">&#8216;Enter with your API Key. You can find this in &#8220;User Profile&#8221; drop-down (top right corner) &gt; API Keys.&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> ),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L38" class="blob-num js-line-number" data-line-number="38"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC38" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;desc_tip&#8217;</span> =&gt; <span class="pl-c1">true</span>,</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L39" class="blob-num js-line-number" data-line-number="39"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC39" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;default&#8217;</span> =&gt; <span class="pl-s">&#8221;</span></td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L40" class="blob-num js-line-number" data-line-number="40"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC40" class="blob-code blob-code-inner js-file-line">),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L41" class="blob-num js-line-number" data-line-number="41"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC41" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;debug&#8217;</span> =&gt; <span class="pl-en">array</span>(</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L42" class="blob-num js-line-number" data-line-number="42"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC42" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;title&#8217;</span> =&gt; <span class="pl-en">__</span>( <span class="pl-s">&#8216;Debug Log&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> ),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L43" class="blob-num js-line-number" data-line-number="43"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC43" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;type&#8217;</span> =&gt; <span class="pl-s">&#8216;checkbox&#8217;</span>,</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L44" class="blob-num js-line-number" data-line-number="44"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC44" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;label&#8217;</span> =&gt; <span class="pl-en">__</span>( <span class="pl-s">&#8216;Enable logging&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> ),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L45" class="blob-num js-line-number" data-line-number="45"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC45" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;default&#8217;</span> =&gt; <span class="pl-s">&#8216;no&#8217;</span>,</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L46" class="blob-num js-line-number" data-line-number="46"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC46" class="blob-code blob-code-inner js-file-line"><span class="pl-s">&#8216;description&#8217;</span> =&gt; <span class="pl-en">__</span>( <span class="pl-s">&#8216;Log events such as API requests&#8217;</span>, <span class="pl-s">&#8216;woocommerce-integration-demo&#8217;</span> ),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L47" class="blob-num js-line-number" data-line-number="47"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC47" class="blob-code blob-code-inner js-file-line">),</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L48" class="blob-num js-line-number" data-line-number="48"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC48" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L49" class="blob-num js-line-number" data-line-number="49"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC49" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L50" class="blob-num js-line-number" data-line-number="50"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC50" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-class-wc-integration-demo-integration-php-L51" class="blob-num js-line-number" data-line-number="51"> </td>
<td id="file-class-wc-integration-demo-integration-php-LC51" class="blob-code blob-code-inner js-file-line"><span class="pl-k">endif</span>;</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<div id="gist88075309" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-integration-demo-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-integration-demo-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-integration-demo-php-LC1" class="blob-code blob-code-inner js-file-line"><span class="pl-ent">&lt;?php</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-integration-demo-php-LC2" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-integration-demo-php-LC3" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Plugin Name: WooCommerce Integration Demo</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-integration-demo-php-LC4" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Plugin URI: https://gist.github.com/BFTrick/091d55feaaef0c5341d8</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-integration-demo-php-LC5" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Description: A plugin demonstrating how to add a new WooCommerce integration.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-integration-demo-php-LC6" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Author: Patrick Rauland</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-integration-demo-php-LC7" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Author URI: http://speakinginbytes.com/</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-integration-demo-php-LC8" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Version: 1.0</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-integration-demo-php-LC9" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> *</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-integration-demo-php-LC10" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * This program is free software: you can redistribute it and/or modify</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-integration-demo-php-LC11" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * it under the terms of the GNU General Public License as published by</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-integration-demo-php-LC12" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * the Free Software Foundation, either version 3 of the License, or</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-integration-demo-php-LC13" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * (at your option) any later version.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-integration-demo-php-LC14" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> *</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-integration-demo-php-LC15" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * This program is distributed in the hope that it will be useful,</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-integration-demo-php-LC16" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-integration-demo-php-LC17" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-integration-demo-php-LC18" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * GNU General Public License for more details.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-wc-integration-demo-php-LC19" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> *</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-wc-integration-demo-php-LC20" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * You should have received a copy of the GNU General Public License</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-wc-integration-demo-php-LC21" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * along with this program. If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-wc-integration-demo-php-LC22" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> *</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-wc-integration-demo-php-LC23" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L24" class="blob-num js-line-number" data-line-number="24"> </td>
<td id="file-wc-integration-demo-php-LC24" class="blob-code blob-code-inner js-file-line"><span class="pl-k">if</span> ( ! <span class="pl-en">class_exists</span>( <span class="pl-s">&#8216;WC_Integration_Demo&#8217;</span> ) ) :</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L25" class="blob-num js-line-number" data-line-number="25"> </td>
<td id="file-wc-integration-demo-php-LC25" class="blob-code blob-code-inner js-file-line"><span class="pl-k">class</span> <span class="pl-v">WC_Integration_Demo</span> {</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L26" class="blob-num js-line-number" data-line-number="26"> </td>
<td id="file-wc-integration-demo-php-LC26" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L27" class="blob-num js-line-number" data-line-number="27"> </td>
<td id="file-wc-integration-demo-php-LC27" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Construct the plugin.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L28" class="blob-num js-line-number" data-line-number="28"> </td>
<td id="file-wc-integration-demo-php-LC28" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L29" class="blob-num js-line-number" data-line-number="29"> </td>
<td id="file-wc-integration-demo-php-LC29" class="blob-code blob-code-inner js-file-line"><span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">__construct</span>() {</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L30" class="blob-num js-line-number" data-line-number="30"> </td>
<td id="file-wc-integration-demo-php-LC30" class="blob-code blob-code-inner js-file-line"><span class="pl-en">add_action</span>( <span class="pl-s">&#8216;plugins_loaded&#8217;</span>, <span class="pl-en">array</span>( <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>, <span class="pl-s">&#8216;init&#8217;</span> ) );</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L31" class="blob-num js-line-number" data-line-number="31"> </td>
<td id="file-wc-integration-demo-php-LC31" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L32" class="blob-num js-line-number" data-line-number="32"> </td>
<td id="file-wc-integration-demo-php-LC32" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L33" class="blob-num js-line-number" data-line-number="33"> </td>
<td id="file-wc-integration-demo-php-LC33" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Initialize the plugin.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L34" class="blob-num js-line-number" data-line-number="34"> </td>
<td id="file-wc-integration-demo-php-LC34" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L35" class="blob-num js-line-number" data-line-number="35"> </td>
<td id="file-wc-integration-demo-php-LC35" class="blob-code blob-code-inner js-file-line"><span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">init</span>() {</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L36" class="blob-num js-line-number" data-line-number="36"> </td>
<td id="file-wc-integration-demo-php-LC36" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// Checks if WooCommerce is installed.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L37" class="blob-num js-line-number" data-line-number="37"> </td>
<td id="file-wc-integration-demo-php-LC37" class="blob-code blob-code-inner js-file-line"><span class="pl-k">if</span> ( <span class="pl-en">class_exists</span>( <span class="pl-s">&#8216;WC_Integration&#8217;</span> ) ) {</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L38" class="blob-num js-line-number" data-line-number="38"> </td>
<td id="file-wc-integration-demo-php-LC38" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// Include our integration class.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L39" class="blob-num js-line-number" data-line-number="39"> </td>
<td id="file-wc-integration-demo-php-LC39" class="blob-code blob-code-inner js-file-line"><span class="pl-k">include_once</span> <span class="pl-s">&#8216;class-wc-integration-demo-integration.php&#8217;</span>;</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L40" class="blob-num js-line-number" data-line-number="40"> </td>
<td id="file-wc-integration-demo-php-LC40" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// Register the integration.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L41" class="blob-num js-line-number" data-line-number="41"> </td>
<td id="file-wc-integration-demo-php-LC41" class="blob-code blob-code-inner js-file-line"><span class="pl-en">add_filter</span>( <span class="pl-s">&#8216;woocommerce_integrations&#8217;</span>, <span class="pl-en">array</span>( <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>, <span class="pl-s">&#8216;add_integration&#8217;</span> ) );</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L42" class="blob-num js-line-number" data-line-number="42"> </td>
<td id="file-wc-integration-demo-php-LC42" class="blob-code blob-code-inner js-file-line">} <span class="pl-k">else</span> {</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L43" class="blob-num js-line-number" data-line-number="43"> </td>
<td id="file-wc-integration-demo-php-LC43" class="blob-code blob-code-inner js-file-line"><span class="pl-c">// throw an admin error if you like</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L44" class="blob-num js-line-number" data-line-number="44"> </td>
<td id="file-wc-integration-demo-php-LC44" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L45" class="blob-num js-line-number" data-line-number="45"> </td>
<td id="file-wc-integration-demo-php-LC45" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L46" class="blob-num js-line-number" data-line-number="46"> </td>
<td id="file-wc-integration-demo-php-LC46" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/**</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L47" class="blob-num js-line-number" data-line-number="47"> </td>
<td id="file-wc-integration-demo-php-LC47" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> * Add a new integration to WooCommerce.</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L48" class="blob-num js-line-number" data-line-number="48"> </td>
<td id="file-wc-integration-demo-php-LC48" class="blob-code blob-code-inner js-file-line"><span class="pl-c"> */</span></td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L49" class="blob-num js-line-number" data-line-number="49"> </td>
<td id="file-wc-integration-demo-php-LC49" class="blob-code blob-code-inner js-file-line"><span class="pl-k">public</span> <span class="pl-k">function</span> <span class="pl-en">add_integration</span>( <span class="pl-s1"><span class="pl-c1">$</span>integrations</span> ) {</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L50" class="blob-num js-line-number" data-line-number="50"> </td>
<td id="file-wc-integration-demo-php-LC50" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span>integrations</span>[] = <span class="pl-s">&#8216;WC_Integration_Demo_Integration&#8217;</span>;</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L51" class="blob-num js-line-number" data-line-number="51"> </td>
<td id="file-wc-integration-demo-php-LC51" class="blob-code blob-code-inner js-file-line"><span class="pl-k">return</span> <span class="pl-s1"><span class="pl-c1">$</span>integrations</span>;</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L52" class="blob-num js-line-number" data-line-number="52"> </td>
<td id="file-wc-integration-demo-php-LC52" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L53" class="blob-num js-line-number" data-line-number="53"> </td>
<td id="file-wc-integration-demo-php-LC53" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L54" class="blob-num js-line-number" data-line-number="54"> </td>
<td id="file-wc-integration-demo-php-LC54" class="blob-code blob-code-inner js-file-line"><span class="pl-s1"><span class="pl-c1">$</span><span class="pl-v">WC_Integration_Demo</span></span> = <span class="pl-k">new</span> <span class="pl-v">WC_Integration_Demo</span>( __FILE__ );</td>
</tr>
<tr>
<td id="file-wc-integration-demo-php-L55" class="blob-num js-line-number" data-line-number="55"> </td>
<td id="file-wc-integration-demo-php-LC55" class="blob-code blob-code-inner js-file-line"><span class="pl-k">endif</span>;</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<div class="gist-meta"> </div>
<p>&nbsp;</p>
</div>
</div>
<h2 id="section-4">Creating Settings</h2>
<p>If you took a look through the last section you’ll see that we added two dummy settings using the <code>init_form_fields()</code> method.</p>
<h3 id="section-5">Types of Settings</h3>
<p>WooCommerce includes support for 8 types of settings.</p>
<ul>
<li>text</li>
<li>price</li>
<li>decimal</li>
<li>password</li>
<li>textarea</li>
<li>checkbox</li>
<li>select</li>
<li>multiselect</li>
</ul>
<p>And these settings have attributes which you can use. These affect the way the setting looks and behaves on the settings page. It doesn’t affect the setting itself. The attributes will manifest slightly differently depending on the setting type. A placeholder for example doesn’t work with checkboxes. To see exactly how they work you should look through the source code. Ex.</p>
<ul>
<li>title</li>
<li>class</li>
<li>css</li>
<li>placeholder</li>
<li>description</li>
<li>default</li>
<li>desc_tip</li>
</ul>
<h3 id="section-6">Creating Your Own Settings</h3>
<p>The built-in settings are great but you may need extra controls to create your settings page. That’s why we included some methods to do this for you.</p>
<p>First create a new setting. And under type enter in whatever new control you want.</p>
<p>Then create a new method to generate the HTML for that input. You can look through the source code for sample code. The below example creates a button that goes to WooThemes.com.</p>
<div id="gist88075356" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-create-custom-setting-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-create-custom-setting-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-create-custom-setting-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-create-custom-setting-php-LC2" class="blob-code blob-code-inner js-file-line">* Initialize integration settings form fields.</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-create-custom-setting-php-LC3" class="blob-code blob-code-inner js-file-line">*</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-create-custom-setting-php-LC4" class="blob-code blob-code-inner js-file-line">* @return void</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-create-custom-setting-php-LC5" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-create-custom-setting-php-LC6" class="blob-code blob-code-inner js-file-line">public function init_form_fields() {</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-create-custom-setting-php-LC7" class="blob-code blob-code-inner js-file-line">$this-<span class="pl-kos">&gt;</span>form_fields = array(</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-create-custom-setting-php-LC8" class="blob-code blob-code-inner js-file-line">// don&#8217;t forget to put your other settings here</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-create-custom-setting-php-LC9" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-create-custom-setting-php-LC10" class="blob-code blob-code-inner js-file-line">&#8216;customize_button&#8217; =<span class="pl-kos">&gt;</span> array(</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-create-custom-setting-php-LC11" class="blob-code blob-code-inner js-file-line">&#8216;title&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Customize!&#8217;, &#8216;woocommerce-integration-demo&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-create-custom-setting-php-LC12" class="blob-code blob-code-inner js-file-line">&#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;button&#8217;,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-create-custom-setting-php-LC13" class="blob-code blob-code-inner js-file-line">&#8216;custom_attributes&#8217; =<span class="pl-kos">&gt;</span> array(</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-create-custom-setting-php-LC14" class="blob-code blob-code-inner js-file-line">&#8216;onclick&#8217; =<span class="pl-kos">&gt;</span> &#8220;location.href=&#8217;http://www.woothemes.com'&#8221;,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-create-custom-setting-php-LC15" class="blob-code blob-code-inner js-file-line">),</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-create-custom-setting-php-LC16" class="blob-code blob-code-inner js-file-line">&#8216;description&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Customize your settings by going to the integration site directly.&#8217;, &#8216;woocommerce-integration-demo&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-create-custom-setting-php-LC17" class="blob-code blob-code-inner js-file-line">&#8216;desc_tip&#8217; =<span class="pl-kos">&gt;</span> true,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-create-custom-setting-php-LC18" class="blob-code blob-code-inner js-file-line">)</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-wc-create-custom-setting-php-LC19" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-wc-create-custom-setting-php-LC20" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-wc-create-custom-setting-php-LC21" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-wc-create-custom-setting-php-LC22" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-wc-create-custom-setting-php-LC23" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L24" class="blob-num js-line-number" data-line-number="24"> </td>
<td id="file-wc-create-custom-setting-php-LC24" class="blob-code blob-code-inner js-file-line">* Generate Button HTML.</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L25" class="blob-num js-line-number" data-line-number="25"> </td>
<td id="file-wc-create-custom-setting-php-LC25" class="blob-code blob-code-inner js-file-line">*</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L26" class="blob-num js-line-number" data-line-number="26"> </td>
<td id="file-wc-create-custom-setting-php-LC26" class="blob-code blob-code-inner js-file-line">* @access public</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L27" class="blob-num js-line-number" data-line-number="27"> </td>
<td id="file-wc-create-custom-setting-php-LC27" class="blob-code blob-code-inner js-file-line">* @param mixed $key</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L28" class="blob-num js-line-number" data-line-number="28"> </td>
<td id="file-wc-create-custom-setting-php-LC28" class="blob-code blob-code-inner js-file-line">* @param mixed $data</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L29" class="blob-num js-line-number" data-line-number="29"> </td>
<td id="file-wc-create-custom-setting-php-LC29" class="blob-code blob-code-inner js-file-line">* @since 1.0.0</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L30" class="blob-num js-line-number" data-line-number="30"> </td>
<td id="file-wc-create-custom-setting-php-LC30" class="blob-code blob-code-inner js-file-line">* @return string</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L31" class="blob-num js-line-number" data-line-number="31"> </td>
<td id="file-wc-create-custom-setting-php-LC31" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L32" class="blob-num js-line-number" data-line-number="32"> </td>
<td id="file-wc-create-custom-setting-php-LC32" class="blob-code blob-code-inner js-file-line">public function generate_button_html( $key, $data ) {</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L33" class="blob-num js-line-number" data-line-number="33"> </td>
<td id="file-wc-create-custom-setting-php-LC33" class="blob-code blob-code-inner js-file-line">$field = $this-<span class="pl-kos">&gt;</span>plugin_id . $this-<span class="pl-kos">&gt;</span>id . &#8216;_&#8217; . $key;</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L34" class="blob-num js-line-number" data-line-number="34"> </td>
<td id="file-wc-create-custom-setting-php-LC34" class="blob-code blob-code-inner js-file-line">$defaults = array(</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L35" class="blob-num js-line-number" data-line-number="35"> </td>
<td id="file-wc-create-custom-setting-php-LC35" class="blob-code blob-code-inner js-file-line">&#8216;class&#8217; =<span class="pl-kos">&gt;</span> &#8216;button-secondary&#8217;,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L36" class="blob-num js-line-number" data-line-number="36"> </td>
<td id="file-wc-create-custom-setting-php-LC36" class="blob-code blob-code-inner js-file-line">&#8216;css&#8217; =<span class="pl-kos">&gt;</span> &#8221;,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L37" class="blob-num js-line-number" data-line-number="37"> </td>
<td id="file-wc-create-custom-setting-php-LC37" class="blob-code blob-code-inner js-file-line">&#8216;custom_attributes&#8217; =<span class="pl-kos">&gt;</span> array(),</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L38" class="blob-num js-line-number" data-line-number="38"> </td>
<td id="file-wc-create-custom-setting-php-LC38" class="blob-code blob-code-inner js-file-line">&#8216;desc_tip&#8217; =<span class="pl-kos">&gt;</span> false,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L39" class="blob-num js-line-number" data-line-number="39"> </td>
<td id="file-wc-create-custom-setting-php-LC39" class="blob-code blob-code-inner js-file-line">&#8216;description&#8217; =<span class="pl-kos">&gt;</span> &#8221;,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L40" class="blob-num js-line-number" data-line-number="40"> </td>
<td id="file-wc-create-custom-setting-php-LC40" class="blob-code blob-code-inner js-file-line">&#8216;title&#8217; =<span class="pl-kos">&gt;</span> &#8221;,</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L41" class="blob-num js-line-number" data-line-number="41"> </td>
<td id="file-wc-create-custom-setting-php-LC41" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L42" class="blob-num js-line-number" data-line-number="42"> </td>
<td id="file-wc-create-custom-setting-php-LC42" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L43" class="blob-num js-line-number" data-line-number="43"> </td>
<td id="file-wc-create-custom-setting-php-LC43" class="blob-code blob-code-inner js-file-line">$data = wp_parse_args( $data, $defaults );</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L44" class="blob-num js-line-number" data-line-number="44"> </td>
<td id="file-wc-create-custom-setting-php-LC44" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L45" class="blob-num js-line-number" data-line-number="45"> </td>
<td id="file-wc-create-custom-setting-php-LC45" class="blob-code blob-code-inner js-file-line">ob_start();</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L46" class="blob-num js-line-number" data-line-number="46"> </td>
<td id="file-wc-create-custom-setting-php-LC46" class="blob-code blob-code-inner js-file-line">?<span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L47" class="blob-num js-line-number" data-line-number="47"> </td>
<td id="file-wc-create-custom-setting-php-LC47" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">tr</span> <span class="pl-c1">valign</span>=&#8221;<span class="pl-s">top</span>&#8220;<span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L48" class="blob-num js-line-number" data-line-number="48"> </td>
<td id="file-wc-create-custom-setting-php-LC48" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">th</span> <span class="pl-c1">scope</span>=&#8221;<span class="pl-s">row</span>&#8221; <span class="pl-c1">class</span>=&#8221;<span class="pl-s">titledesc</span>&#8220;<span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L49" class="blob-num js-line-number" data-line-number="49"> </td>
<td id="file-wc-create-custom-setting-php-LC49" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">label</span> <span class="pl-c1">for</span>=&#8221;<span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">esc_attr</span>( <span class="pl-s1"><span class="pl-c1">$</span>field</span> ); <span class="pl-ent">?&gt;</span>&#8220;<span class="pl-kos">&gt;</span><span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">wp_kses_post</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span>[<span class="pl-s">&#8216;title&#8217;</span>] ); <span class="pl-ent">?&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">label</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L50" class="blob-num js-line-number" data-line-number="50"> </td>
<td id="file-wc-create-custom-setting-php-LC50" class="blob-code blob-code-inner js-file-line"><span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get_tooltip_html</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span> ); <span class="pl-ent">?&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L51" class="blob-num js-line-number" data-line-number="51"> </td>
<td id="file-wc-create-custom-setting-php-LC51" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;/</span><span class="pl-ent">th</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L52" class="blob-num js-line-number" data-line-number="52"> </td>
<td id="file-wc-create-custom-setting-php-LC52" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">td</span> <span class="pl-c1">class</span>=&#8221;<span class="pl-s">forminp</span>&#8220;<span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L53" class="blob-num js-line-number" data-line-number="53"> </td>
<td id="file-wc-create-custom-setting-php-LC53" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">fieldset</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L54" class="blob-num js-line-number" data-line-number="54"> </td>
<td id="file-wc-create-custom-setting-php-LC54" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">legend</span> <span class="pl-c1">class</span>=&#8221;<span class="pl-s">screen-reader-text</span>&#8220;<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;</span><span class="pl-ent">span</span><span class="pl-kos">&gt;</span><span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">wp_kses_post</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span>[<span class="pl-s">&#8216;title&#8217;</span>] ); <span class="pl-ent">?&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">span</span><span class="pl-kos">&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">legend</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L55" class="blob-num js-line-number" data-line-number="55"> </td>
<td id="file-wc-create-custom-setting-php-LC55" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;</span><span class="pl-ent">button</span> <span class="pl-c1">class</span>=&#8221;<span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">esc_attr</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span>[<span class="pl-s">&#8216;class&#8217;</span>] ); <span class="pl-ent">?&gt;</span>&#8221; <span class="pl-c1">type</span>=&#8221;<span class="pl-s">button</span>&#8221; <span class="pl-c1">name</span>=&#8221;<span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">esc_attr</span>( <span class="pl-s1"><span class="pl-c1">$</span>field</span> ); <span class="pl-ent">?&gt;</span>&#8221; <span class="pl-c1">id</span>=&#8221;<span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">esc_attr</span>( <span class="pl-s1"><span class="pl-c1">$</span>field</span> ); <span class="pl-ent">?&gt;</span>&#8221; <span class="pl-c1">style</span>=&#8221;<span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">esc_attr</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span>[<span class="pl-s">&#8216;css&#8217;</span>] ); <span class="pl-ent">?&gt;</span>&#8221; <span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get_custom_attribute_html</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span> ); <span class="pl-ent">?&gt;</span><span class="pl-kos">&gt;</span><span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-en">wp_kses_post</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span>[<span class="pl-s">&#8216;title&#8217;</span>] ); <span class="pl-ent">?&gt;</span><span class="pl-kos">&lt;/</span><span class="pl-ent">button</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L56" class="blob-num js-line-number" data-line-number="56"> </td>
<td id="file-wc-create-custom-setting-php-LC56" class="blob-code blob-code-inner js-file-line"><span class="pl-ent">&lt;?php</span> <span class="pl-k">echo</span> <span class="pl-s1"><span class="pl-c1">$</span><span class="pl-smi">this</span></span>-&gt;<span class="pl-en">get_description_html</span>( <span class="pl-s1"><span class="pl-c1">$</span>data</span> ); <span class="pl-ent">?&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L57" class="blob-num js-line-number" data-line-number="57"> </td>
<td id="file-wc-create-custom-setting-php-LC57" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;/</span><span class="pl-ent">fieldset</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L58" class="blob-num js-line-number" data-line-number="58"> </td>
<td id="file-wc-create-custom-setting-php-LC58" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;/</span><span class="pl-ent">td</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L59" class="blob-num js-line-number" data-line-number="59"> </td>
<td id="file-wc-create-custom-setting-php-LC59" class="blob-code blob-code-inner js-file-line"><span class="pl-kos">&lt;/</span><span class="pl-ent">tr</span><span class="pl-kos">&gt;</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L60" class="blob-num js-line-number" data-line-number="60"> </td>
<td id="file-wc-create-custom-setting-php-LC60" class="blob-code blob-code-inner js-file-line"><span class="pl-ent">&lt;?php</span></td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L61" class="blob-num js-line-number" data-line-number="61"> </td>
<td id="file-wc-create-custom-setting-php-LC61" class="blob-code blob-code-inner js-file-line"><span class="pl-k">return</span> <span class="pl-en">ob_get_clean</span>();</td>
</tr>
<tr>
<td id="file-wc-create-custom-setting-php-L62" class="blob-num js-line-number" data-line-number="62"> </td>
<td id="file-wc-create-custom-setting-php-LC62" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<h2 id="section-7">Validating &amp; Sanitizing Data</h2>
<p>To create the best user experience you’ll most likely want to validate and sanitize your data. The integration class already performs basic sanitization so that there’s no malicious code present but you could further sanitize by removing unused data. An example of sanitizing data would be integrating with a 3rd party service where all API keys are upper case. You could convert the API key to upper case which will make it a bit more clear for the user.</p>
<h3 id="section-8">Sanitize</h3>
<p>I’m going to show you how to sanitize data first because it’s a bit easier to understand. But the one thing you should keep in mind is that sanitizing happens <em>after</em> validation. So if something isn’t validated it won’t get to the sanitization step.</p>
<div id="gist88075383" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-sanitize-settings-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-sanitize-settings-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-sanitize-settings-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-sanitize-settings-php-LC2" class="blob-code blob-code-inner js-file-line">* Init and hook in the integration.</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-sanitize-settings-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-sanitize-settings-php-LC4" class="blob-code blob-code-inner js-file-line">public function __construct() {</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-sanitize-settings-php-LC5" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-sanitize-settings-php-LC6" class="blob-code blob-code-inner js-file-line">// do other constructor stuff first</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-sanitize-settings-php-LC7" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-sanitize-settings-php-LC8" class="blob-code blob-code-inner js-file-line">// Filters.</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-sanitize-settings-php-LC9" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_settings_api_sanitized_fields_&#8217; . $this-<span class="pl-kos">&gt;</span>id, array( $this, &#8216;sanitize_settings&#8217; ) );</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-sanitize-settings-php-LC10" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-sanitize-settings-php-LC11" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-sanitize-settings-php-LC12" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-sanitize-settings-php-LC13" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-sanitize-settings-php-LC14" class="blob-code blob-code-inner js-file-line">* Sanitize our settings</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-sanitize-settings-php-LC15" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-sanitize-settings-php-LC16" class="blob-code blob-code-inner js-file-line">public function sanitize_settings( $settings ) {</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-sanitize-settings-php-LC17" class="blob-code blob-code-inner js-file-line">// We&#8217;re just going to make the api key all upper case characters since that&#8217;s how our imaginary API works</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-sanitize-settings-php-LC18" class="blob-code blob-code-inner js-file-line">if ( isset( $settings ) &amp;&amp;</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-wc-sanitize-settings-php-LC19" class="blob-code blob-code-inner js-file-line">isset( $settings[&#8216;api_key&#8217;] ) ) {</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-wc-sanitize-settings-php-LC20" class="blob-code blob-code-inner js-file-line">$settings[&#8216;api_key&#8217;] = strtoupper( $settings[&#8216;api_key&#8217;] );</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-wc-sanitize-settings-php-LC21" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-wc-sanitize-settings-php-LC22" class="blob-code blob-code-inner js-file-line">return $settings;</td>
</tr>
<tr>
<td id="file-wc-sanitize-settings-php-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-wc-sanitize-settings-php-LC23" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<h3 id="section-9">Validation</h3>
<p>Validation isn’t always necessary but it’s nice to do. If your API keys are always 10 characters long and someone enters one that’s not 10 then you can print out an error message and prevent the user a lot of headache when they assumed they put it in correctly.</p>
<p>First set up a <code>validate_{setting key}_field</code> method for each field you want to validate. For example, with the <code>api_key</code> field you need a <code>validate_api_key_field()</code> method.</p>
<div id="gist88075399" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-validate-settings-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-validate-settings-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-validate-settings-php-LC1" class="blob-code blob-code-inner js-file-line">public function validate_api_key_field( $key, $value ) {</td>
</tr>
<tr>
<td id="file-wc-validate-settings-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-validate-settings-php-LC2" class="blob-code blob-code-inner js-file-line">if ( isset( $value ) &amp;&amp; 20 <span class="pl-kos">&lt;</span> <span class="pl-ent">strlen</span><span class="pl-c1">(</span> <span class="pl-c1">$value</span> <span class="pl-c1">)</span> <span class="pl-c1">)</span> <span class="pl-c1">{</span></td>
</tr>
<tr>
<td id="file-wc-validate-settings-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-validate-settings-php-LC3" class="blob-code blob-code-inner js-file-line"><span class="pl-c1">WC_Admin_Settings::add_error(</span> <span class="pl-c1">esc_html__(</span> &#8216;Looks like you made a mistake with the API Key field. Make sure it isn&amp;apos;t longer than 20 characters&#8217;, &#8216;woocommerce-integration-demo&#8217; ) );</td>
</tr>
<tr>
<td id="file-wc-validate-settings-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-validate-settings-php-LC4" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-validate-settings-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-validate-settings-php-LC5" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-validate-settings-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-validate-settings-php-LC6" class="blob-code blob-code-inner js-file-line">return $value;</td>
</tr>
<tr>
<td id="file-wc-validate-settings-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-validate-settings-php-LC7" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<h2 id="section-10">A complete example<a class="woodocs-top-link" title="Back to top" href="https://help.codibu.com/blog/kb/implementing-the…ntegration-class/#doc-title">#</a></h2>
<p>If you’ve been following along you should have a complete integration example. If you have any problems see our full integration demo.</p><p>The post <a href="https://help.codibu.com/blog/implementing-the-wc-integration-class/">Implementing the WC Integration Class</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/implementing-the-wc-integration-class/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WC_API – The WooCommerce API Callback</title>
		<link>https://help.codibu.com/blog/wc_api-the-woocommerce-api-callback/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wc_api-the-woocommerce-api-callback</link>
					<comments>https://help.codibu.com/blog/wc_api-the-woocommerce-api-callback/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:02:55 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/wc_api-the-woocommerce-api-callback/</guid>

					<description><![CDATA[<p>The WooCommerce API allows plugins make a callback to a special URL that will then load the specified class (if it exists) and run an action. This is<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/wc_api-the-woocommerce-api-callback/">WC_API – The WooCommerce API Callback</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>The WooCommerce API allows plugins make a callback to a special URL that will then load the specified class (if it exists) and run an action. This is also useful for gateways that are not initialized.</p>
<p>You can view the <a title="http://docs.woocommerce.com/wc-apidocs/class-WC_API.html" href="http://docs.woocommerce.com/wc-apidocs/class-WC_API.html">WC_API class in our docs</a>.</p>
<h2 id="section-1">Callback URL</h2>
<p>To trigger the WooCommerce API, you need to use a special URL. Before WooCommerce 2.0, you could use:</p>
<pre>http://yoursite.com/?wc-api=CALLBACK</pre>
<p>In WooCommerce 2.0+,  you can still use that or use our endpoint:</p>
<pre>http://yoursite.com/wc-api/CALLBACK/</pre>
<p>When this URL is called, WooCommerce:</p>
<ol>
<li>Initializes the CALLBACK class, if it exists</li>
<li>Triggers an action based on the callback: <strong>woocommerce_api_callback</strong>. Note: CALLBACK will be sanitized and lower case.</li>
<li>Exit WordPress.</li>
</ol>
<h2 id="section-2">Hooking into the callback</h2>
<p>Add an action to hook into the callback hook. For example:</p>
<pre>add_action( 'woocommerce_api_callback', 'callback_handler' );</pre>
<p>WooCommerce will exit after that action, but you can still redirect the user elsewhere from your handler if you wish.</p><p>The post <a href="https://help.codibu.com/blog/wc_api-the-woocommerce-api-callback/">WC_API – The WooCommerce API Callback</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/wc_api-the-woocommerce-api-callback/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Importing WooCommerce Sample Data</title>
		<link>https://help.codibu.com/blog/importing-woocommerce-sample-data/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=importing-woocommerce-sample-data</link>
					<comments>https://help.codibu.com/blog/importing-woocommerce-sample-data/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:02:27 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/importing-woocommerce-sample-data/</guid>

					<description><![CDATA[<p>Your store may look empty, right after installing WooCommerce — no products, orders, reviews. This is intentional so you can get started creating your own products<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/importing-woocommerce-sample-data/">Importing WooCommerce Sample Data</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Your store may look empty, right after installing WooCommerce — no products, orders, reviews. This is intentional so you can get started creating your own products and setting up WooCommerce exactly as you need.</p>
<p>But maybe you’d like to see what a store full of sample orders and products looks like. If so, we’ve got some data for you!</p>
<p>Sample data for WooCommerce is located in a file called either <code>sample-products.csv</code> or <code>sample-products.xml</code>, which are located in the WooCommerce plugin folder in <code>woocommerce/sample-data/</code>. You can get it in two ways:</p>
<ul>
<li>Re-download <a href="http://wordpress.org/extend/plugins/woocommerce/">WooCommerce.</a> Open the .zip and find the files in the folder.</li>
<li>Get the file from your site via SFTP, etc.</li>
</ul>
<h2 id="section-1">Import via WooCommerce Products</h2>
<p><strong>This is the recommended approach.</strong></p>
<p>From the WordPress Dashboard:</p>
<ol>
<li>Go to: <strong>Products &gt; All Products</strong>.</li>
<li>Select <strong>Import</strong>.</li>
<li><strong>Run Importer</strong>. An <strong>Import Products</strong> screen appears.<br />
<a href="https://help.codibu.com/wp-content/uploads/2020/11/importproducts-dummydata.png"><img fetchpriority="high" decoding="async" class="aligncenter size-full wp-image-10691" src="https://help.codibu.com/wp-content/uploads/2020/11/importproducts-dummydata.png" alt="" width="1990" height="1098" /></a></li>
<li>Select <strong>Choose file</strong> and then select the <strong>sample-products.csv </strong>file you downloaded.</li>
<li><strong>Continue</strong>. A Column Mapping screen appears.
</li>
<li>Scroll down and <strong>Run the Importer</strong>.<br />
<a href="https://help.codibu.com/wp-content/uploads/2020/11/runimporter-dummydata.png"><img decoding="async" class="aligncenter wp-image-10717 size-full" src="https://help.codibu.com/wp-content/uploads/2020/11/runimporter-dummydata.png" alt="" width="1448" height="786" /></a></li>
</ol>
<p>You now have sample data in WooCommerce to learn from.</p>
<h2 id="section-2">Import via WordPress Importer</h2>
<p>From the WordPress Dashboard:</p>
<ol>
<li>Go to: <strong>Tools &gt; Import</strong>.</li>
<li>Select <strong>WordPress</strong>.<br />
<a href="https://help.codibu.com/wp-content/uploads/2020/11/wordpress-importer-dummydata.png"><img decoding="async" class="aligncenter size-full wp-image-10854" src="https://help.codibu.com/wp-content/uploads/2020/11/wordpress-importer-dummydata.png" alt="" width="2048" height="1509" /></a></li>
<li><strong>Run Importer</strong>.</li>
<li>Select <strong>Choose file</strong> and then select the <strong>sample-products.xml </strong>file you downloaded.</li>
<li><strong>Upload file and import</strong>.</li>
<li><strong>Import</strong> our default wooteam author, <strong>create a new user</strong>, <strong>or assign the posts to an existing user</strong>. This is your call to make, though we recommend assigning the posts to an existing user.</li>
<li>Tick or untick the box for <strong>Download and import file attachments</strong>. This imports all sample product images to your site if ticked.<br />
<a href="https://help.codibu.com/wp-content/uploads/2020/11/choosing-an-author.png"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-10673" src="https://help.codibu.com/wp-content/uploads/2020/11/choosing-an-author.png" alt="" width="1614" height="728" /></a></li>
<li><strong>Submit</strong> and your sample data is imported.</li>
</ol><p>The post <a href="https://help.codibu.com/blog/importing-woocommerce-sample-data/">Importing WooCommerce Sample Data</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/importing-woocommerce-sample-data/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Removing /product/ , /product-category/ , or /shop/ from the URLs</title>
		<link>https://help.codibu.com/blog/removing-product-product-category-or-shop-from-the-urls/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=removing-product-product-category-or-shop-from-the-urls</link>
					<comments>https://help.codibu.com/blog/removing-product-product-category-or-shop-from-the-urls/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:01:59 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/removing-product-product-category-or-shop-from-the-urls/</guid>

					<description><![CDATA[<p>In sum Removing /product/, /product-category/, or /shop/ from the URLs is not advisable due to the way WordPress resolves its URLs. It uses the product-category (or any other text for that matter)<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/removing-product-product-category-or-shop-from-the-urls/">Removing /product/ , /product-category/ , or /shop/ from the URLs</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<h2 id="section-1">In sum</h2>
<p>Removing <code>/product/</code>, <code>/product-category/</code>, or <code>/shop/</code> from the URLs is not advisable due to the way WordPress resolves its URLs. It uses the <code>product-category</code> (or any other text for that matter) base of an URL to detect that it is an URL leading to a product category.</p>
<p>There are SEO plugins that allow you to remove this base, but that can lead to a number of problems with performance and duplicate URLs.</p>
<h2 id="section-2">Better to avoid</h2>
<p>You will make it harder for WordPress to detect what page you are trying to reach when you type in a product category URL.</p>
<p>Also, understand that the standard “Page” in WordPress always has no base text in the URL. For example:</p>
<ul>
<li>http://yoursite.com/about-page/ (this is the URL of a standard page)</li>
<li>http://yoursite.com/about-page/product-category/category-x/ (this is the URL leading to a product category)</li>
</ul>
<p>What would happen if we remove that ‘product-category’ part?</p>
<ul>
<li>http://yoursite.com/about-page/about-page/</li>
<li>http://yoursite.com/about-page/category-x/</li>
</ul>
<p>WordPress will have to do much more work to detect what page you are looking for when entering one of the above URLs. That is why we do not recommend using any SEO plugin to achieve this.</p><p>The post <a href="https://help.codibu.com/blog/removing-product-product-category-or-shop-from-the-urls/">Removing /product/ , /product-category/ , or /shop/ from the URLs</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/removing-product-product-category-or-shop-from-the-urls/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WooCommerce Hooks: Actions and filters</title>
		<link>https://help.codibu.com/blog/woocommerce-hooks-actions-and-filters/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=woocommerce-hooks-actions-and-filters</link>
					<comments>https://help.codibu.com/blog/woocommerce-hooks-actions-and-filters/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:01:26 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/woocommerce-hooks-actions-and-filters/</guid>

					<description><![CDATA[<p>Introduction: What are hooks? Hooks in WordPress essentially allow you to change or add code without editing core files. They are used extensively throughout WordPress and WooCommerce<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/woocommerce-hooks-actions-and-filters/">WooCommerce Hooks: Actions and filters</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<h2 id="section-1">Introduction: What are hooks?</h2>
<p><strong>Hooks</strong> in WordPress essentially allow you to change or add code without editing core files. They are used extensively throughout WordPress and WooCommerce and are very useful for developers.</p>
<p>There are two types of hook: actions and filters.</p>
<ul>
<li><strong>Action </strong>Hooks allow you to insert custom code at various points (wherever the hook is run).</li>
<li><strong>Filter </strong>Hooks allow you to manipulate and return a variable which it passes (for instance a product price).</li>
</ul>
<p>There is an older article on hooks and filters here.</p>
<p>&nbsp;</p>
<div class="woo-sc-box note   "><b>Note:</b> This is a <strong>Developer level</strong> documentation. We are unable to provide support for customizations under our <a href="https://help.codibu.com/blog/kb/support-policy/"><span class="s2">Support Policy</span></a>. If you are unfamiliar with code/templates and resolving potential conflicts, select a <a href="https://woocommerce.com/customizations/"><span class="s2">WooExpert or Developer</span></a> for assistance.</div>
<p>&nbsp;</p>
<h2 id="section-2">Using hooks</h2>
<p>If you use a hook to add or manipulate code, you can add your custom code in a variety of ways:</p>
<ul>
<li>To a <a href="https://help.codibu.com/blog/kb/customizing-woocommerce-best-practices/#section-7">custom child theme’s <code>functions.php</code> file</a>.</li>
<li>Using a plugin such as Code Snippets.</li>
</ul>
<h3 id="section-3">Using action hooks</h3>
<p>To execute your own code, you hook in by using the action hook <code>do_action('action_name');</code>. Here is where to place your code:</p>
<pre class="brush: php; gutter: false">add_action( 'action_name', 'your_function_name' );

function your_function_name() {
// Your code
}
</pre>
<h3 id="section-4">Using filter hooks</h3>
<p>Filter hooks are called throughout are code using <code>apply_filter( 'filter_name', $variable );</code>.<strong> </strong>To manipulate the passed variable, you can do something like the following:</p>
<pre class="brush: php; gutter: false">add_filter( 'filter_name', 'your_function_name' );

function your_function_name( $variable ) {
// Your code
return $variable;
}</pre>
<p>With filters, you must return a value.</p>
<p>To learn more about options for using hooks and filters see our <a title="WooCommerce Snippets" href="https://docs.woocommerce.com/documentation/plugins/woocommerce/woocommerce-codex/snippets/">Snippet</a> doc section.</p>
<h2 id="section-5">Example</h2>
<p>In the example below, both action hooks and filter hooks are used. This tutorial teaches you how to change and add fields to the checkout.</p>
<ul>
<li>Actions are used to:
<ul>
<li>Add a new field to the checkout</li>
<li>Add that new field to the order</li>
</ul>
</li>
<li>Filters are used to:
<ul>
<li>Override the labels and placeholders of existing fields</li>
<li>Make an existing field optional while it used to be required</li>
<li>Remove existing fields</li>
</ul>
</li>
</ul>
<blockquote class="wp-embedded-content" data-secret="0HOuKa9ZAD">
<p><a href="https://help.codibu.com/blog/kb/customizing-checkout-fields-using-actions-and-filters/">Customizing checkout fields using actions and filters</a></p>
</blockquote>
<h2 id="section-6">API Documentation</h2>
<p>For a comprehensive view of the WooCommerce API, see the <a href="https://docs.woocommerce.com/wc-apidocs/index.html" target="_blank" rel="noopener noreferrer">API Documentation</a>.</p>
<h2 id="section-7">Available WooCommerce action hooks and filters</h2>
<p>For details on what the action hooks and filters do, reference the <a href="https://docs.woocommerce.com/wc-apidocs/hooks/hooks.html" target="_blank" rel="noopener noreferrer">WooCommerce Hooks Reference</a>.</p><p>The post <a href="https://help.codibu.com/blog/woocommerce-hooks-actions-and-filters/">WooCommerce Hooks: Actions and filters</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/woocommerce-hooks-actions-and-filters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Customizing checkout fields using actions and filters</title>
		<link>https://help.codibu.com/blog/customizing-checkout-fields-using-actions-and-filters/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=customizing-checkout-fields-using-actions-and-filters</link>
					<comments>https://help.codibu.com/blog/customizing-checkout-fields-using-actions-and-filters/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:00:56 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/customizing-checkout-fields-using-actions-and-filters/</guid>

					<description><![CDATA[<p>If you are unfamiliar with code and resolving potential conflicts, we have an extension that can help: WooCommerce Checkout Field Editor. Installing and activating this extension overrides<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/customizing-checkout-fields-using-actions-and-filters/">Customizing checkout fields using actions and filters</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>If you are unfamiliar with code and resolving potential conflicts, we have an extension that can help: <a title="WooCommerce Checkout Field Editor" href="https://help.codibu.com/blog/kb/checkout-field-editor/">WooCommerce Checkout Field Editor</a>. Installing and activating this extension overrides any code below that you try to implement; and you cannot have custom checkout field code in your functions.php file when the extension is activated.</p>
<p>Custom code should be copied into your child theme’s <strong>functions.php</strong> file.</p>
<h2 id="section-1">How Are Checkout Fields Loaded to WooCommerce?</h2>
<p>The billing and shipping fields for checkout pull from the countries class (<code>class-wc-countries.php</code>) and the <strong><code>get_address_fields</code></strong> function. This allows WooCommerce to enable/disable fields based on the user’s location.</p>
<p>Before returning these fields, WooCommerce puts the fields through a <em>filter</em>. This allows them to be edited by third-party plugins, themes and your own custom code.</p>
<p>Billing:</p>
<pre class="brush: php; gutter: false">$address_fields = apply_filters('woocommerce_billing_fields', $address_fields);</pre>
<p>Shipping:</p>
<pre class="brush: php; gutter: false">$address_fields = apply_filters('woocommerce_shipping_fields', $address_fields);</pre>
<p>The checkout class adds the loaded fields to its ‘checkout_fields’ array, as well as adding a few other fields like “order notes”.</p>
<pre class="brush: php; gutter: true">$this-&gt;checkout_fields['billing']    = $woocommerce-&gt;countries-&gt;get_address_fields( $this-&gt;get_value('billing_country'), 'billing_' );
$this-&gt;checkout_fields['shipping']   = $woocommerce-&gt;countries-&gt;get_address_fields( $this-&gt;get_value('shipping_country'), 'shipping_' );
$this-&gt;checkout_fields['account']    = array(
    'account_username' =&gt; array(
        'type' =&gt; 'text',
        'label' =&gt; __('Account username', 'woocommerce'),
        'placeholder' =&gt; _x('Username', 'placeholder', 'woocommerce')
        ),
    'account_password' =&gt; array(
        'type' =&gt; 'password',
        'label' =&gt; __('Account password', 'woocommerce'),
        'placeholder' =&gt; _x('Password', 'placeholder', 'woocommerce'),
        'class' =&gt; array('form-row-first')
        ),
    'account_password-2' =&gt; array(
        'type' =&gt; 'password',
        'label' =&gt; __('Account password', 'woocommerce'),
        'placeholder' =&gt; _x('Password', 'placeholder', 'woocommerce'),
        'class' =&gt; array('form-row-last'),
        'label_class' =&gt; array('hidden')
        )
    );
$this-&gt;checkout_fields['order']  = array(
    'order_comments' =&gt; array(
        'type' =&gt; 'textarea',
        'class' =&gt; array('notes'),
        'label' =&gt; __('Order Notes', 'woocommerce'),
        'placeholder' =&gt; _x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')
        )
    );</pre>
<p>This array is also passed through a filter:</p>
<pre class="brush: php; gutter: false">$this-&gt;checkout_fields = apply_filters('woocommerce_checkout_fields', $this-&gt;checkout_fields);</pre>
<p>That means you have <strong>full control</strong> over checkout fields – you only need to know how to access them.</p>
<h2 id="section-2">Overriding Core Fields</h2>
<p>Hooking into the <strong> <code>woocommerce_checkout_fields</code> </strong>filter lets you override any field. As an example, let’s change the placeholder on the order_comments fields. Currently, it’s set to:</p>
<pre>_x('Notes about your order, e.g. special notes for delivery.', 'placeholder', 'woocommerce')</pre>
<p>We can change this by adding a function to our theme functions.php file:</p>
<pre class="brush: php; gutter: true">// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['order']['order_comments']['placeholder'] = 'My new placeholder';
     return $fields;
}</pre>
<p>You can override other parts, such as labels:</p>
<pre class="brush: php; gutter: true">// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     $fields['order']['order_comments']['placeholder'] = 'My new placeholder';
     $fields['order']['order_comments']['label'] = 'My new label';
     return $fields;
}</pre>
<p>Or remove fields:</p>
<pre class="brush: php; gutter: true">// Hook in
add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );

// Our hooked in function - $fields is passed via the filter!
function custom_override_checkout_fields( $fields ) {
     unset($fields['order']['order_comments']);

     return $fields;
}</pre>
<p>Here’s a full list of fields in the array passed to <code>woocommerce_checkout_fields</code>:</p>
<ul>
<li>Billing
<ul>
<li><code>billing_first_name</code></li>
<li><code>billing_last_name</code></li>
<li><code>billing_company</code></li>
<li><code>billing_address_1</code></li>
<li><code>billing_address_2</code></li>
<li><code>billing_city</code></li>
<li><code>billing_postcode</code></li>
<li><code>billing_country</code></li>
<li><code>billing_state</code></li>
<li><code>billing_email</code></li>
<li><code>billing_phone</code></li>
</ul>
</li>
<li>Shipping
<ul>
<li><code>shipping_first_name</code></li>
<li><code>shipping_last_name</code></li>
<li><code>shipping_company</code></li>
<li><code>shipping_address_1</code></li>
<li><code>shipping_address_2</code></li>
<li><code>shipping_city</code></li>
<li><code>shipping_postcode</code></li>
<li><code>shipping_country</code></li>
<li><code>shipping_state</code></li>
</ul>
</li>
<li>Account
<ul>
<li><code>account_username</code></li>
<li><code>account_password</code></li>
<li><code>account_password-2</code></li>
</ul>
</li>
<li>Order
<ul>
<li><code>order_comments</code></li>
</ul>
</li>
</ul>
<p>Each field contains an array of properties:</p>
<ul>
<li><code>type</code> – type of field (text, textarea, password, select)</li>
<li><code>label</code> – label for the input field</li>
<li><code>placeholder</code> – placeholder for the input</li>
<li><code>class</code> – class for the input</li>
<li><code>required</code> – true or false, whether or not the field is require</li>
<li><code>clear</code> – true or false, applies a clear fix to the field/label</li>
<li><code>label_class</code> – class for the label element</li>
<li><code>options</code> – for select boxes, array of options (key =&gt; value pairs)</li>
</ul>
<p>In specific cases you need to use the <strong><code>woocommerce_default_address_fields</code></strong> filter. This filter is applied to all billing and shipping default fields:</p>
<ul>
<li><code>country</code></li>
<li><code>first_name</code></li>
<li><code>last_name</code></li>
<li><code>company</code></li>
<li><code>address_1</code></li>
<li><code>address_2</code></li>
<li><code>city</code></li>
<li><code>state</code></li>
<li><code>postcode</code></li>
</ul>
<p>For example, to make the <code>address_1</code> field optional:</p>
<pre class="brush: php; gutter: true">// Hook in
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );

// Our hooked in function - $address_fields is passed via the filter!
function custom_override_default_address_fields( $address_fields ) {
     $address_fields['address_1']['required'] = false;

     return $address_fields;
}</pre>
<h3 id="section-3">Defining select options</h3>
<p>If you are adding a field with type ‘select’, as stated above you would define key/value pairs. For example:</p>
<pre class="brush: php; gutter: true">$fields['billing']['your_field']['options'] = array(
  'option_1' =&gt; 'Option 1 text',
  'option_2' =&gt; 'Option 2 text'
);</pre>
<h2 id="section-4">Priority</h2>
<p>Priority in regards to PHP code helps establish when a bit of code — called a function — runs in relation to a page load. It is set inside of each function and is useful when overriding existing code for custom display.</p>
<p>Code with a higher number set as the priority will run after code with a lower number, meaning code with a priority of 20 will run after code with 10 priority.</p>
<p>The priority argument is set during the add_action function, after you establish which hook you’re connecting to and what the name of your custom function will be.</p>
<p>In the example below, blue text is the name of the hook we’re modifying, green text is the name of our custom function, and red is the priority we set.</p>
<p><a href="https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png" rel="prettyPhoto"><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-340222" src="https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png" sizes="(max-width: 980px) 100vw, 980px" srcset="https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png 1576w, https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png?resize=550,45 550w, https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png?resize=768,63 768w, https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png?resize=950,78 950w, https://help.codibu.com/wp-content/uploads/2012/04/priority-markup.png?resize=1536,127 1536w" alt="" width="980" height="81" /></a></p>
<h3 id="section-5">Examples</h3>
<p>In this example, the code is set to redirect the “Return to Shop” button found in the cart to a category that lists products for sale at http://example.url/category/specials/.</p>
<div id="gist88073122" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-empty-cart-redirect-url-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC2" class="blob-code blob-code-inner js-file-line">* Changes the redirect URL for the Return To Shop button in the cart.</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC4" class="blob-code blob-code-inner js-file-line">function wc_empty_cart_redirect_url() {</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC5" class="blob-code blob-code-inner js-file-line">return &#8216;http://example.url/category/specials/&#8217;;</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC6" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-empty-cart-redirect-url-php-LC7" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_return_to_shop_redirect&#8217;, &#8216;wc_empty_cart_redirect_url&#8217;, 10 );</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>There, we can see the priority is set to 10. This is the typical default for WooCommerce functions and scripts, so that may not be sufficient to override that button’s functionality.</p>
<p>Instead, we can change the priority to any number greater than 10. While 11 would work, best practice dictates we use increments of ten, so 20, 30, and so on.</p>
<div id="gist88073239" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-empty-cart-redirect-url-priority-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC2" class="blob-code blob-code-inner js-file-line">* Changes the redirect URL for the Return To Shop button in the cart.</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC4" class="blob-code blob-code-inner js-file-line">function wc_empty_cart_redirect_url() {</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC5" class="blob-code blob-code-inner js-file-line">return &#8216;http://example.com/category/specials/&#8217;;</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC6" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-priority-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-empty-cart-redirect-url-priority-php-LC7" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_return_to_shop_redirect&#8217;, &#8216;wc_empty_cart_redirect_url&#8217;, 20 );</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>With priority, we can have two functions that are acting on the same hook. Normally this would cause a variety of problems, but since we’ve established one has a higher priority than the other, our site will only load the appropriate function, and we will be taken to the Specials page as intended with the code below.</p>
<div id="gist88073303" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-empty-cart-redirect-url-double-snippet-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC2" class="blob-code blob-code-inner js-file-line">* Changes the redirect URL for the Return To Shop button in the cart.</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC3" class="blob-code blob-code-inner js-file-line">* BECAUSE THIS FUNCTION HAS THE PRIORITY OF 20, IT WILL RUN AFTER THE FUNCTION BELOW (HIGHER NUMBERS RUN LATER)</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC4" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC5" class="blob-code blob-code-inner js-file-line">function wc_empty_cart_redirect_url() {</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC6" class="blob-code blob-code-inner js-file-line">return &#8216;http://example.com/category/specials/&#8217;;</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC7" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC8" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_return_to_shop_redirect&#8217;, &#8216;wc_empty_cart_redirect_url&#8217;, 20 );</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC9" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC10" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC11" class="blob-code blob-code-inner js-file-line">* Changes the redirect URL for the Return To Shop button in the cart.</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC12" class="blob-code blob-code-inner js-file-line">* EVEN THOUGH THIS FUNCTION WOULD NORMALLY RUN LATER BECAUSE IT&#8217;S CODED AFTERWARDS, THE 10 PRIORITY IS LOWER THAN 20 ABOVE</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC13" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC14" class="blob-code blob-code-inner js-file-line">function wc_empty_cart_redirect_url() {</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC15" class="blob-code blob-code-inner js-file-line">return &#8216;http://example.com/shop/&#8217;;</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC16" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-empty-cart-redirect-url-double-snippet-php-LC17" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_return_to_shop_redirect&#8217;, &#8216;wc_empty_cart_redirect_url&#8217;, 10 );</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<h2 id="section-6">Adding Custom Shipping And Billing Fields</h2>
<p>Adding fields is done in a similar way to overriding fields. For example, let’s add a new field to shipping fields – <code>shipping_phone</code>:</p>
<div id="gist88073373" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-override-checkout-fields-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-override-checkout-fields-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-override-checkout-fields-php-LC1" class="blob-code blob-code-inner js-file-line">// Hook in</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-override-checkout-fields-php-LC2" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_checkout_fields&#8217; , &#8216;custom_override_checkout_fields&#8217; );</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-override-checkout-fields-php-LC3" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-override-checkout-fields-php-LC4" class="blob-code blob-code-inner js-file-line">// Our hooked in function – $fields is passed via the filter!</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-override-checkout-fields-php-LC5" class="blob-code blob-code-inner js-file-line">function custom_override_checkout_fields( $fields ) {</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-override-checkout-fields-php-LC6" class="blob-code blob-code-inner js-file-line">$fields[&#8216;shipping&#8217;][&#8216;shipping_phone&#8217;] = array(</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-override-checkout-fields-php-LC7" class="blob-code blob-code-inner js-file-line">&#8216;label&#8217; =<span class="pl-kos">&gt;</span> __(&#8216;Phone&#8217;, &#8216;woocommerce&#8217;),</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-override-checkout-fields-php-LC8" class="blob-code blob-code-inner js-file-line">&#8216;placeholder&#8217; =<span class="pl-kos">&gt;</span> _x(&#8216;Phone&#8217;, &#8216;placeholder&#8217;, &#8216;woocommerce&#8217;),</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-override-checkout-fields-php-LC9" class="blob-code blob-code-inner js-file-line">&#8216;required&#8217; =<span class="pl-kos">&gt;</span> false,</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-override-checkout-fields-php-LC10" class="blob-code blob-code-inner js-file-line">&#8216;class&#8217; =<span class="pl-kos">&gt;</span> array(&#8216;form-row-wide&#8217;),</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-override-checkout-fields-php-LC11" class="blob-code blob-code-inner js-file-line">&#8216;clear&#8217; =<span class="pl-kos">&gt;</span> true</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-override-checkout-fields-php-LC12" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-override-checkout-fields-php-LC13" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-override-checkout-fields-php-LC14" class="blob-code blob-code-inner js-file-line">return $fields;</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-override-checkout-fields-php-LC15" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-override-checkout-fields-php-LC16" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-override-checkout-fields-php-LC17" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-override-checkout-fields-php-LC18" class="blob-code blob-code-inner js-file-line">* Display field value on the order edit page</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-wc-override-checkout-fields-php-LC19" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-wc-override-checkout-fields-php-LC20" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-wc-override-checkout-fields-php-LC21" class="blob-code blob-code-inner js-file-line">add_action( &#8216;woocommerce_admin_order_data_after_shipping_address&#8217;, &#8216;my_custom_checkout_field_display_admin_order_meta&#8217;, 10, 1 );</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-wc-override-checkout-fields-php-LC22" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-wc-override-checkout-fields-php-LC23" class="blob-code blob-code-inner js-file-line">function my_custom_checkout_field_display_admin_order_meta($order){</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L24" class="blob-num js-line-number" data-line-number="24"> </td>
<td id="file-wc-override-checkout-fields-php-LC24" class="blob-code blob-code-inner js-file-line">echo &#8216;<span class="pl-kos">&lt;</span><span class="pl-ent">p</span><span class="pl-kos">&gt;</span><span class="pl-kos">&lt;</span><span class="pl-ent">strong</span><span class="pl-kos">&gt;</span>&#8216;.__(&#8216;Phone From Checkout Form&#8217;).&#8217;:<span class="pl-kos">&lt;/</span><span class="pl-ent">strong</span><span class="pl-kos">&gt;</span> &#8216; . get_post_meta( $order-<span class="pl-kos">&gt;</span>get_id(), &#8216;_shipping_phone&#8217;, true ) . &#8216;<span class="pl-kos">&lt;/</span><span class="pl-ent">p</span><span class="pl-kos">&gt;</span>&#8216;;</td>
</tr>
<tr>
<td id="file-wc-override-checkout-fields-php-L25" class="blob-num js-line-number" data-line-number="25"> </td>
<td id="file-wc-override-checkout-fields-php-LC25" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<figure id="attachment_156738" class="wp-caption aligncenter" aria-describedby="caption-attachment-156738"><a href="https://help.codibu.com/wp-content/uploads/2012/04/WooCommerce-Codex-Shipping-Field-Hook.png" rel="prettyPhoto"><img loading="lazy" decoding="async" class="size-full wp-image-156738" src="https://help.codibu.com/wp-content/uploads/2012/04/WooCommerce-Codex-Shipping-Field-Hook.png" alt="It's alive!" width="432" height="794" /></a><figcaption id="caption-attachment-156738" class="wp-caption-text">It’s alive!</figcaption></figure>
<p>What do we do with the new field? Nothing. Because we defined the field in the checkout_fields array, the field is automatically processed and saved to the order post meta (in this case, _shipping_phone). If you want to add validation rules, see the checkout class where there are additional hooks you can use.</p>
<h2 id="section-7">Adding a Custom Special Field</h2>
<p>To add a custom field is similar. Let’s add a new field to checkout, after the order notes, by hooking into the following:</p>
<div id="gist88073495" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-custom-checkout-field-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-custom-checkout-field-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-custom-checkout-field-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-custom-checkout-field-php-LC2" class="blob-code blob-code-inner js-file-line">* Add the field to the checkout</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-custom-checkout-field-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-custom-checkout-field-php-LC4" class="blob-code blob-code-inner js-file-line">add_action( &#8216;woocommerce_after_order_notes&#8217;, &#8216;my_custom_checkout_field&#8217; );</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-custom-checkout-field-php-LC5" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-custom-checkout-field-php-LC6" class="blob-code blob-code-inner js-file-line">function my_custom_checkout_field( $checkout ) {</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-custom-checkout-field-php-LC7" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-custom-checkout-field-php-LC8" class="blob-code blob-code-inner js-file-line">echo &#8216;<span class="pl-kos">&lt;</span><span class="pl-ent">div</span> <span class="pl-c1">id</span>=&#8221;<span class="pl-s">my_custom_checkout_field</span>&#8220;<span class="pl-kos">&gt;</span><span class="pl-kos">&lt;</span><span class="pl-ent">h2</span><span class="pl-kos">&gt;</span>&#8216; . __(&#8216;My Field&#8217;) . &#8216;<span class="pl-kos">&lt;/</span><span class="pl-ent">h2</span><span class="pl-kos">&gt;</span>&#8216;;</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-custom-checkout-field-php-LC9" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-custom-checkout-field-php-LC10" class="blob-code blob-code-inner js-file-line">woocommerce_form_field( &#8216;my_field_name&#8217;, array(</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-custom-checkout-field-php-LC11" class="blob-code blob-code-inner js-file-line">&#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;text&#8217;,</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-custom-checkout-field-php-LC12" class="blob-code blob-code-inner js-file-line">&#8216;class&#8217; =<span class="pl-kos">&gt;</span> array(&#8216;my-field-class form-row-wide&#8217;),</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-custom-checkout-field-php-LC13" class="blob-code blob-code-inner js-file-line">&#8216;label&#8217; =<span class="pl-kos">&gt;</span> __(&#8216;Fill in this field&#8217;),</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-custom-checkout-field-php-LC14" class="blob-code blob-code-inner js-file-line">&#8216;placeholder&#8217; =<span class="pl-kos">&gt;</span> __(&#8216;Enter something&#8217;),</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-custom-checkout-field-php-LC15" class="blob-code blob-code-inner js-file-line">), $checkout-<span class="pl-kos">&gt;</span>get_value( &#8216;my_field_name&#8217; ));</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-custom-checkout-field-php-LC16" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-custom-checkout-field-php-LC17" class="blob-code blob-code-inner js-file-line">echo &#8216;<span class="pl-kos">&lt;/</span><span class="pl-ent">div</span><span class="pl-kos">&gt;</span>&#8216;;</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-custom-checkout-field-php-LC18" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-php-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-wc-custom-checkout-field-php-LC19" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>This gives us:</p>
<p><a href="https://help.codibu.com/wp-content/uploads/2012/04/WooCommerce-Codex-Checkout-Field-Hook.png" rel="prettyPhoto"><img loading="lazy" decoding="async" class=" size-full wp-image-156742 aligncenter" src="https://help.codibu.com/wp-content/uploads/2012/04/WooCommerce-Codex-Checkout-Field-Hook.png" alt="WooCommerce Codex - Checkout Field Hook" width="323" height="748" /></a></p>
<p>Next we need to validate the field when the checkout form is posted. For this example the field is required and not optional:</p>
<div id="gist88073563" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-process-checkout-field-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-process-checkout-field-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-process-checkout-field-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-process-checkout-field-php-LC2" class="blob-code blob-code-inner js-file-line">* Process the checkout</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-process-checkout-field-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-process-checkout-field-php-LC4" class="blob-code blob-code-inner js-file-line">add_action(&#8216;woocommerce_checkout_process&#8217;, &#8216;my_custom_checkout_field_process&#8217;);</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-process-checkout-field-php-LC5" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-process-checkout-field-php-LC6" class="blob-code blob-code-inner js-file-line">function my_custom_checkout_field_process() {</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-process-checkout-field-php-LC7" class="blob-code blob-code-inner js-file-line">// Check if set, if its not set add an error.</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-process-checkout-field-php-LC8" class="blob-code blob-code-inner js-file-line">if ( ! $_POST[&#8216;my_field_name&#8217;] )</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-process-checkout-field-php-LC9" class="blob-code blob-code-inner js-file-line">wc_add_notice( __( &#8216;Please enter something into this new shiny field.&#8217; ), &#8216;error&#8217; );</td>
</tr>
<tr>
<td id="file-wc-process-checkout-field-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-process-checkout-field-php-LC10" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>A checkout error is displayed if the field is blank:</p>
<p><a href="https://help.codibu.com/wp-content/uploads/2012/04/WooCommerce-Codex-Checkout-Field-Notice.png" rel="prettyPhoto"><img loading="lazy" decoding="async" class=" size-full wp-image-156745 aligncenter" src="https://help.codibu.com/wp-content/uploads/2012/04/WooCommerce-Codex-Checkout-Field-Notice.png" alt="WooCommerce Codex - Checkout Field Notice" width="599" height="865" /></a></p>
<p>Finally, let’s save the new field to order custom fields using the following code:</p>
<div id="gist88073617" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-save-custom-checkout-field-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC2" class="blob-code blob-code-inner js-file-line">* Update the order meta with field value</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC4" class="blob-code blob-code-inner js-file-line">add_action( &#8216;woocommerce_checkout_update_order_meta&#8217;, &#8216;my_custom_checkout_field_update_order_meta&#8217; );</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC5" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC6" class="blob-code blob-code-inner js-file-line">function my_custom_checkout_field_update_order_meta( $order_id ) {</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC7" class="blob-code blob-code-inner js-file-line">if ( ! empty( $_POST[&#8216;my_field_name&#8217;] ) ) {</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC8" class="blob-code blob-code-inner js-file-line">update_post_meta( $order_id, &#8216;My Field&#8217;, sanitize_text_field( $_POST[&#8216;my_field_name&#8217;] ) );</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC9" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-save-custom-checkout-field-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-save-custom-checkout-field-php-LC10" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>The field is now saved to the order.</p>
<p>If you wish to display the custom field value on the admin order edition page, you can add this code:</p>
<div id="gist88073673" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-display-custom-checkout-field-order-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC1" class="blob-code blob-code-inner js-file-line">/**</td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC2" class="blob-code blob-code-inner js-file-line">* Display field value on the order edit page</td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC3" class="blob-code blob-code-inner js-file-line">*/</td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC4" class="blob-code blob-code-inner js-file-line">add_action( &#8216;woocommerce_admin_order_data_after_billing_address&#8217;, &#8216;my_custom_checkout_field_display_admin_order_meta&#8217;, 10, 1 );</td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC5" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC6" class="blob-code blob-code-inner js-file-line">function my_custom_checkout_field_display_admin_order_meta($order){</td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC7" class="blob-code blob-code-inner js-file-line">echo &#8216;<span class="pl-kos">&lt;</span><span class="pl-ent">p</span><span class="pl-kos">&gt;</span><span class="pl-kos">&lt;</span><span class="pl-ent">strong</span><span class="pl-kos">&gt;</span>&#8216;.__(&#8216;My Field&#8217;).&#8217;:<span class="pl-kos">&lt;/</span><span class="pl-ent">strong</span><span class="pl-kos">&gt;</span> &#8216; . get_post_meta( $order-<span class="pl-kos">&gt;</span>id, &#8216;My Field&#8217;, true ) . &#8216;<span class="pl-kos">&lt;/</span><span class="pl-ent">p</span><span class="pl-kos">&gt;</span>&#8216;;</td>
</tr>
<tr>
<td id="file-wc-display-custom-checkout-field-order-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-display-custom-checkout-field-order-php-LC8" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>This is the result:</p>
<p><a href="https://help.codibu.com/wp-content/uploads/2012/04/checkout_field_custom_field_admin.png"><img loading="lazy" decoding="async" class="size-full wp-image-151612 aligncenter" src="https://help.codibu.com/wp-content/uploads/2012/04/checkout_field_custom_field_admin.png" sizes="(max-width: 660px) 100vw, 660px" srcset="https://help.codibu.com/wp-content/uploads/2012/04/checkout_field_custom_field_admin.png 660w, https://help.codibu.com/wp-content/uploads/2012/04/checkout_field_custom_field_admin.png?resize=462,550 462w" alt="checkout_field_custom_field_admin" width="660" height="785" /></a></p>
<h3 id="section-8">Example: Make phone number not required</h3>
<div id="gist88073735" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-custom-checkout-field-not-required-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-custom-checkout-field-not-required-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-custom-checkout-field-not-required-php-LC1" class="blob-code blob-code-inner js-file-line">add_filter( &#8216;woocommerce_billing_fields&#8217;, &#8216;wc_npr_filter_phone&#8217;, 10, 1 );</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-not-required-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-custom-checkout-field-not-required-php-LC2" class="blob-code blob-code-inner js-file-line">function wc_npr_filter_phone( $address_fields ) {</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-not-required-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-custom-checkout-field-not-required-php-LC3" class="blob-code blob-code-inner js-file-line">$address_fields[&#8216;billing_phone&#8217;][&#8216;required&#8217;] = false;</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-not-required-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-custom-checkout-field-not-required-php-LC4" class="blob-code blob-code-inner js-file-line">return $address_fields;</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-not-required-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-custom-checkout-field-not-required-php-LC5" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<h2 id="section-9">Adding Custom Fields To Emails</h2>
<p>To add a custom field value to WooCommerce emails — a completed order email, for example — use the following snippet:</p>
<div id="gist88073785" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-custom-checkout-field-display-in-emails-php-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-hack  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC1" class="blob-code blob-code-inner js-file-line"><span class="pl-c">/* To use: </span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC2" class="blob-code blob-code-inner js-file-line"><span class="pl-c">1. Add this snippet to your theme&#8217;s functions.php file</span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC3" class="blob-code blob-code-inner js-file-line"><span class="pl-c">2. Change the meta key names in the snippet</span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC4" class="blob-code blob-code-inner js-file-line"><span class="pl-c">3. Create a custom field in the order post – e.g. key = &#8220;Tracking Code&#8221; value = abcdefg</span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC5" class="blob-code blob-code-inner js-file-line"><span class="pl-c">4. When next updating the status, or during any other event which emails the user, they will see this field in their email</span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC6" class="blob-code blob-code-inner js-file-line"><span class="pl-c">*/</span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC7" class="blob-code blob-code-inner js-file-line"><span class="pl-en">add_filter</span>(<span class="pl-s"><span class="pl-pds">&#8216;</span>woocommerce_email_order_meta_keys<span class="pl-pds">&#8216;</span></span>, <span class="pl-s"><span class="pl-pds">&#8216;</span>my_custom_order_meta_keys<span class="pl-pds">&#8216;</span></span>);</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC8" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC9" class="blob-code blob-code-inner js-file-line"><span class="pl-k">function</span> <span class="pl-en">my_custom_order_meta_keys</span>( <span class="pl-smi">$keys</span> ) {</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC10" class="blob-code blob-code-inner js-file-line"><span class="pl-smi">$keys</span>[] <span class="pl-k">=</span> <span class="pl-s"><span class="pl-pds">&#8216;</span>Tracking Code<span class="pl-pds">&#8216;</span></span>; <span class="pl-c">// This will look for a custom field called &#8216;Tracking Code&#8217; and add it to emails</span></td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC11" class="blob-code blob-code-inner js-file-line"><span class="pl-k">return</span> <span class="pl-smi">$keys</span>;</td>
</tr>
<tr>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-custom-checkout-field-display-in-emails-php-php-LC12" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div><p>The post <a href="https://help.codibu.com/blog/customizing-checkout-fields-using-actions-and-filters/">Customizing checkout fields using actions and filters</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/customizing-checkout-fields-using-actions-and-filters/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Using custom attributes in menus and taxonomy archives</title>
		<link>https://help.codibu.com/blog/using-custom-attributes-in-menus-and-taxonomy-archives/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-custom-attributes-in-menus-and-taxonomy-archives</link>
					<comments>https://help.codibu.com/blog/using-custom-attributes-in-menus-and-taxonomy-archives/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 16:00:00 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/using-custom-attributes-in-menus-and-taxonomy-archives/</guid>

					<description><![CDATA[<p>Attributes that can be used for the layered nav are a custom taxonomy, which means you can display them in menus, or display products by attributes.<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/using-custom-attributes-in-menus-and-taxonomy-archives/">Using custom attributes in menus and taxonomy archives</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Attributes that can be used for the layered nav are a custom taxonomy, which means you can display them in menus, or display products by attributes. This requires some work on your part, and archives must be enabled.</p>
<div class="woo-sc-box note   "><b>Note:</b> This is a <b>Developer level</b> doc. If you are unfamiliar with code/templates and resolving potential conflicts, select a <a href="https://woocommerce.com/customizations/"><span class="s2">WooExpert or Developer</span></a> for assistance. We are unable to provide support for customizations under our<span class="Apple-converted-space">  </span><a href="https://help.codibu.com/blog/kb/support-policy/"><span class="s2">Support Policy</span></a>.</div>
<h1 id="register-the-taxonomy-for-menus">Register the taxonomy for menus</h1>
<p>When registering taxonomies for your custom attributes, WooCommerce calls the following hook:</p>
<pre class="brush: php; gutter: false">$show_in_nav_menus = apply_filters('woocommerce_attribute_show_in_nav_menus', false, $name);</pre>
<p>So, for example, if your attribute slug was ‘size’ you would do the following to register it for menus:</p>
<pre class="brush: php; gutter: true">add_filter('woocommerce_attribute_show_in_nav_menus', 'wc_reg_for_menus', 1, 2);

function wc_reg_for_menus( $register, $name = '' ) {
     if ( $name == 'pa_size' ) $register = true;
     return $register;
}</pre>
<div class="woo-sc-box note   ">Custom attribute slugs are prefixed with ‘pa_’, so an attribute called ‘size’ would be ‘pa_size’</div>
<p>Now use your attribute in <strong>Appearance &gt; Menus</strong>. You will notice, however, that it has default blog styling when you click on a link to your taxonomy term.</p>
<h1 id="create-a-template">Create a template</h1>
<p>You need to theme your attribute to make it display products as you want. To do this:</p>
<ol>
<li>Copy woocommerce/templates/taxonomy-product_cat.php into your theme folder</li>
<li>Rename the template to reflect your attribute – in our example we’d use taxonomy-pa_size.php</li>
</ol>
<p>You should now see this template when viewing taxonomy terms for your custom attribute.</p><p>The post <a href="https://help.codibu.com/blog/using-custom-attributes-in-menus-and-taxonomy-archives/">Using custom attributes in menus and taxonomy archives</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/using-custom-attributes-in-menus-and-taxonomy-archives/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>WooCommerce Plugin Developer Handbook</title>
		<link>https://help.codibu.com/blog/woocommerce-plugin-developer-handbook/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=woocommerce-plugin-developer-handbook</link>
					<comments>https://help.codibu.com/blog/woocommerce-plugin-developer-handbook/#respond</comments>
		
		<dc:creator><![CDATA[JN C]]></dc:creator>
		<pubDate>Sun, 08 Nov 2020 15:59:21 +0000</pubDate>
				<guid isPermaLink="false">https://help.codibu.com/kb/woocommerce-plugin-developer-handbook/</guid>

					<description><![CDATA[<p>Want to create a plugin to extend WooCommerce? WooCommerce plugins are the same as regular WordPress plugins. For more information, visit Writing a plugin. Your WooCommerce extension<span class="excerpt-hellip"> […]</span></p>
<p>The post <a href="https://help.codibu.com/blog/woocommerce-plugin-developer-handbook/">WooCommerce Plugin Developer Handbook</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Want to create a plugin to extend WooCommerce? WooCommerce plugins are the same as regular WordPress plugins. For more information, visit Writing a plugin.</p>
<p>Your WooCommerce extension should:</p>
<ul>
<li>Adhere to all WordPress plugin coding standards, as well as best practice guidelines for harmonious existence within WordPress and alongside other WordPress plugins.</li>
<li>Have a single core purpose and use WooCommerce features as much as possible.</li>
<li>Not do anything malicious or underhanded — for example, inserting spam links or up selling services outside of the WooCommerce.com ecosystem.</li>
<li>Not subvert or override Marketplace connections in core — for example, extensions cannot create branded top level menu items or introduce their own telemetry.</li>
</ul>
<p>Merchants make use of WooCommerce extensions daily, and should have an unified and pleasant experience while doing so without advertising invading their WP Admin or store.</p>
<p>Note: We provide this page as a best practice for developers.</p>
<p class="p1"> </p>
<div class="woo-sc-box note   "><b>Note:</b> We are unable to provide support for custom code under our <a href="https://help.codibu.com/blog/kb/support-policy/"><span class="s2">Support Policy</span></a>. If you are unfamiliar with code and resolving potential conflicts, select a <a href="https://woocommerce.com/customizations/"><span class="s2">WooExpert or Developer</span></a>  for assistance.</div>
<p>&nbsp;</p>
<h2 id="section-1">Check if WooCommerce is active</h2>
<p>Most WooCommerce plugins do not need to run unless WooCommerce is already active. You can wrap your plugin in a check to see if WooCommerce is installed:</p>
<pre class="brush: php; gutter: false">/**
 * Check if WooCommerce is active
 **/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
    // Put your plugin code here
}</pre>
<p>Note that this check will fail if the WC plugin folder is named anything other than <code>woocommerce</code>.</p>
<h2 id="section-2">Main file naming</h2>
<p>The main plugin file should adopt the name of the plugin, e.g., A plugin with the directory name <code>plugin-name</code> would have its main file named <code>plugin-name.php</code>.</p>
<h2 id="section-3">Text domains</h2>
<p>Follow guidelines for Internationalization for WordPress Developers, the text domain should match your plugin directory name, e.g., A plugin with a directory name of <code>plugin-name</code> would have the text domain <code>plugin-name</code>. Do not use underscores.</p>
<h2 id="section-4">Localization</h2>
<p>All text strings within the plugin code should be in <strong>English</strong>. This is the WordPress default locale, and English should always be the first language. If your plugin is intended for a specific market (e.g., Spain or Italy), include appropriate translation files for those languages within your plugin package. Learn more at Using Makepot to translate your plugin.</p>
<h2 id="section-5">Follow WordPress PHP Guidelines</h2>
<p>WordPress has a set of guidelines to keep all WordPress code consistent and easy to read. This includes quotes, indentation, brace style, shorthand php tags, yoda conditions, naming conventions, and more. Please review the guidelines.</p>
<p>Code conventions also prevent basic mistakes, as Apple made with iOS 7.0.6.</p>
<h2 id="section-6">Custom Database Tables &amp; Data Storage</h2>
<p>Avoid creating custom database tables. Whenever possible, use WordPress post types, taxonomies, and options.</p>
<p>Consider the permanence of your data. Here’s a quick primer:</p>
<ul>
<li>If the data may not always be present (i.e., it expires), use a <strong>transient</strong>.</li>
<li>If the data is persistent but not always present, consider using the <strong>WP Cache</strong>.</li>
<li>If the data is persistent and always present, consider the <strong><code>wp_options</code></strong> table.</li>
<li>If the data type is an entity with <code>n</code> units, consider a <strong>post type</strong>.</li>
<li>If the data is a means or sorting/categorizing an entity, consider a <strong>taxonomy</strong>.</li>
</ul>
<p>Logs should be written to a file using the <code>WC_Logger</code> class.</p>
<h2 id="section-7">Prevent Data Leaks</h2>
<p>Try to prevent direct access data leaks. Add this line of code after the opening PHP tag in each PHP file:</p>
<pre class="brush: php; gutter: false">if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}</pre>
<h2 id="section-8">Readme</h2>
<p>All plugins need a standard WordPress readme.</p>
<p>Your readme might look something like this:</p>
<pre class="brush: php; gutter: false">=== Plugin Name ===
Contributors: (this should be a list of wordpress.org userid's)
Tags: comments, spam
Requires at least: 4.0.1
Tested up to: 4.3
Requires PHP: 5.6
Stable tag: 4.3
License: GPLv3 or later License
URI: http://www.gnu.org/licenses/gpl-3.0.html</pre>
<h2 id="section-9">Plugin Author Name</h2>
<p>Consistency is important to us and our customers. Products offered through WooCommerce.com should provide a consistent experience for all aspects of the product, including finding information on who to contact with queries.</p>
<p>Customers should be able to easily to differentiate a product purchased at WooCommerce.com from a product purchased elsewhere, just by looking through their plugin list in WordPress.</p>
<p>Thus, the following plugin headers should be in place:</p>
<ul>
<li>The <code>Plugin Author</code> is<code>YourName/YourCompany</code></li>
<li>The <code>Developer</code> header is <code>YourName/YourCompany</code>, with the <code>Developer URI</code> field listed as <code>http://yourdomain.com/</code></li>
</ul>
<p>For example:</p>
<pre class="brush: php; gutter: false">/**
 * Plugin Name: WooCommerce Extension
 * Plugin URI: http://woocommerce.com/products/woocommerce-extension/
 * Description: Your extension's description text.
 * Version: 1.0.0
 * Author: Your Name
 * Author URI: http://yourdomain.com/
 * Developer: Your Name
 * Developer URI: http://yourdomain.com/
 * Text Domain: woocommerce-extension
 * Domain Path: /languages
 *
 * Woo: 12345:342928dfsfhsf8429842374wdf4234sfd
 * WC requires at least: 2.2
 * WC tested up to: 2.3
 *
 * License: GNU General Public License v3.0
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */</pre>
<h2 id="section-10">Declaring required and supported WooCommerce version</h2>
<p>Use the follow headers to declare “required” and “tested up to” versions:</p>
<ul>
<li>WC requires at least</li>
<li>WC tested up to</li>
</ul>
<h3 id="section-11">Plugin URI</h3>
<p>Ensure that the <code>Plugin URI</code> line of the above plugin header is provided. This line should contain the URL of the plugin’s product/sale page on WooCommerce.com (if sold by WooCommerce) or to a dedicated page for the plugin on your website.</p>
<h2 id="section-12">Woo Plugin Header For Updates</h2>
<p>WooCommerce core looks for a <code>Woo</code> line in the plugin header comment, to ensure it can check for updates to your plugin, on WooCommerce.com. This line looks like this:</p>
<p><code>Woo: 12345:342928dfsfhsf8429842374wdf4234sfd</code></p>
<p>This is<strong> only required for products sold on WooCommerce.com. </strong> Using this line for products listed on WordPress.org or elsewhere is not required or necessary.</p>
<p>For products sold on WooCommerce.com, Vendors can find this snippet by logging in to their logging in to the Vendors Dashboard and going to <b>Extensions &gt; All Extensions.</b> Then, select<b> </b>the product and click <b>Edit product page.</b> This snippet will be in the upper-right-hand corner of the screen.</p>
<p><a href="https://help.codibu.com/wp-content/uploads/2020/11/woo-plugin-header-meta-box.png"><img loading="lazy" decoding="async" class="size-medium wp-image-995817 alignnone" src="https://help.codibu.com/wp-content/uploads/2020/11/woo-plugin-header-meta-box.png?w=292" alt="" width="292" height="153" /></a></p>
<p>See the plugin header comment example above for how the <code>Woo</code> header looks in context.</p>
<h2 id="section-13">Make it Extensible</h2>
<p>Developers should use WordPress actions and filters to allow for modification/customization without requiring users to touch the plugin’s core code base.</p>
<p>If your plugin creates a front-end output, we recommend to having a templating engine in place so users can create custom template files in their theme’s WooCommerce folder to overwrite the plugin’s template files.</p>
<div class="woo-sc-box info   ">For more information, check out Pippin’s post on Writing Extensible Plugins with Actions and Filters.</div>
<h2 id="section-14">Remove Unused Code</h2>
<p>With version control, there’s no reason to leave commented-out code; it’s annoying to scroll through and read. Remove it and add it back later if needed.</p>
<h2 id="section-15">Comment</h2>
<p>If you have a function, what does the function do? There should be comments for most if not all functions in your code. Someone/You may want to modify the plugin, and comments are helpful for that. We recommend using PHP Doc Blocks  similar to WooCommerce.</p>
<h2 id="section-16">Avoid God Objects</h2>
<p>God Objects are objects that know or do too much. The point of object-oriented programming is to take a large problem and break it into smaller parts. When functions do too much, it’s hard to follow their logic, making bugs harder to fix. Instead of having massive functions, break them down into smaller pieces.</p>
<h2 id="section-17">Test Your Code with WP_DEBUG</h2>
<p>Always develop with WP_DEBUG mode on, so you can see all PHP warnings sent to the screen. This will flag things like making sure a variable is set before checking the value.</p>
<h2 id="section-18">Separate Business Logic &amp; Presentation Logic</h2>
<p>It’s a good practice to separate business logic (i.e., how the plugin works) from presentation logic (i.e., how it looks). Two separate pieces of logic are more easily maintained and swapped if necessary. An example is to have two different classes — one for displaying the end results, and one for the admin settings page.</p>
<h2 id="section-19">Use Transients to Store Offsite Information</h2>
<p>If you provide a service via an API, it’s best to store that information so future queries can be done faster and the load on your service is lessened. WordPress transients can be used to store data for a certain amount of time.</p>
<h2 id="section-20">Logging Data</h2>
<p>You may want to log data that can be useful for debugging purposes. This is great with two conditions:</p>
<ul>
<li>Allow any logging as an ‘opt in’.</li>
<li>Use the <a title="WC_Logger class" href="http://docs.woocommerce.com/wc-apidocs/class-WC_Logger.html">WC_Logger</a> class. A user can then view logs on their system status page.</li>
</ul>
<p>If adding logging to your extension, here’s a snippet for presenting a link to the logs, in a way the extension user can easily make use of.</p>
<div id="gist88072608" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-wc-view-log-setting-snippet-php" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-php  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC1" class="blob-code blob-code-inner js-file-line">$label = __( &#8216;Enable Logging&#8217;, &#8216;your-textdomain-here&#8217; );</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC2" class="blob-code blob-code-inner js-file-line">$description = __( &#8216;Enable the logging of errors.&#8217;, &#8216;your-textdomain-here&#8217; );</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC3" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC4" class="blob-code blob-code-inner js-file-line">if ( defined( &#8216;WC_LOG_DIR&#8217; ) ) {</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC5" class="blob-code blob-code-inner js-file-line">$log_url = add_query_arg( &#8216;tab&#8217;, &#8216;logs&#8217;, add_query_arg( &#8216;page&#8217;, &#8216;wc-status&#8217;, admin_url( &#8216;admin.php&#8217; ) ) );</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC6" class="blob-code blob-code-inner js-file-line">$log_key = &#8216;your-plugin-slug-here-&#8216; . sanitize_file_name( wp_hash( &#8216;your-plugin-slug-here&#8217; ) ) . &#8216;-log&#8217;;</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC7" class="blob-code blob-code-inner js-file-line">$log_url = add_query_arg( &#8216;log_file&#8217;, $log_key, $log_url );</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC8" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC9" class="blob-code blob-code-inner js-file-line">$label .= &#8216; | &#8216; . sprintf( __( &#8216;%1$sView Log%2$s&#8217;, &#8216;your-textdomain-here&#8217; ), &#8216;<span class="pl-kos">&lt;</span><span class="pl-ent">a</span> <span class="pl-c1">href</span>=&#8221;<span class="pl-s">&#8216; . esc_url( $log_url ) . &#8216;</span>&#8220;<span class="pl-kos">&gt;</span>&#8216;, &#8216;<span class="pl-kos">&lt;/</span><span class="pl-ent">a</span><span class="pl-kos">&gt;</span>&#8216; );</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC10" class="blob-code blob-code-inner js-file-line">}</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC11" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC12" class="blob-code blob-code-inner js-file-line">$form_fields[&#8216;wc_yourpluginslug_debug&#8217;] = array(</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC13" class="blob-code blob-code-inner js-file-line">&#8216;title&#8217; =<span class="pl-kos">&gt;</span> __( &#8216;Debug Log&#8217;, &#8216;your-textdomain-here&#8217; ),</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC14" class="blob-code blob-code-inner js-file-line">&#8216;label&#8217; =<span class="pl-kos">&gt;</span> $label,</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC15" class="blob-code blob-code-inner js-file-line">&#8216;description&#8217; =<span class="pl-kos">&gt;</span> $description,</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC16" class="blob-code blob-code-inner js-file-line">&#8216;type&#8217; =<span class="pl-kos">&gt;</span> &#8216;checkbox&#8217;,</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC17" class="blob-code blob-code-inner js-file-line">&#8216;default&#8217; =<span class="pl-kos">&gt;</span> &#8216;no&#8217;</td>
</tr>
<tr>
<td id="file-wc-view-log-setting-snippet-php-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-wc-view-log-setting-snippet-php-LC18" class="blob-code blob-code-inner js-file-line">);</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<h2 id="section-21">Error codes</h2>
<p>This information is intended for the third-party developers so products they write can better handle errors. Error codes are produced by the Product Build Server when uploading a new submission or updating an existing product on the Marketplace.</p>
<h3 id="error-0">error_success</h3>
<p>The operation has completed successfully.</p>
<h3 id="error-1001">error_pbs_prepare_apache</h3>
<p>Internal error with the Product Build Server – cannot initialize the Apache daemon.</p>
<h3 id="error-1002">error_pbs_prepare_mysql</h3>
<p>Internal error with the Product Build Server – cannot initialize the MySQL daemon.</p>
<h3 id="error-1003">error_pbs_prepare_wp</h3>
<p>Internal error with the Product Build Server – cannot initialize WordPress.</p>
<h3 id="error-1004">error_pbs_prepare_wc</h3>
<p>Internal error with the Product Build Server – cannot initialize WooCommerce.</p>
<h3 id="error-1005">error_pbs_prepare_dependencies</h3>
<p>Internal error with the Product Build Server – cannot configure dependencies.</p>
<h3 id="error-1006">error_pbs_test_malware_scanning</h3>
<p>Malware scanning error. This can happen if your product contains malware in the code.</p>
<p>Here’s an example output:</p>
<pre>ObfuscatedPhp /tmp/product_clone/woocommerce-example/includes/views/html-settings-page.php
0x406:$ini_set:  ini_set(
0x506:$ini_set:  ini_set(
ObfuscatedPhp /tmp/product_clone/woocommerce-example/includes/views/html-extras-page.php
0x406:$eval:  exec(
</pre>
<p>This means that the character at the absolute position 0x406 (1030) and 0x506 (1286) in the file <code>html-settings-page.php</code> doesn’t pass the <code>$ini_set</code> rule, because it is using <code>call_user_func</code> in that file. Also, the other file <code>html-extras-page.php</code> doesn’t pass the rule <code>$register_function</code> which is using <code>exec</code> call.</p>
<h3 id="error-1007">error_pbs_test_extracting</h3>
<p>Cannot extract the product. Most common issue is the top directory of the zip does not match its slug.</p>
<h3 id="error-1008">error_pbs_test_phpcs</h3>
<p><code>phpcs</code> checks failed. The check uses the WooCommerce-Core sniffs with following <code>phpcs.xml</code>:</p>
<div id="gist105301572" class="gist">
<div class="gist-file">
<div class="gist-data">
<div class="js-gist-file-update-container js-task-list-container file-box">
<div id="file-phpcs-xml" class="file my-2">
<div class="Box-body p-0 blob-wrapper data type-xml  ">
<table class="highlight tab-size js-file-line-container" data-tab-size="8" data-paste-markdown-skip="">
<tbody>
<tr>
<td id="file-phpcs-xml-L1" class="blob-num js-line-number" data-line-number="1"> </td>
<td id="file-phpcs-xml-LC1" class="blob-code blob-code-inner js-file-line">&lt;?<span class="pl-ent">xml</span><span class="pl-e"> version</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>1.0<span class="pl-pds">&#8220;</span></span>?&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L2" class="blob-num js-line-number" data-line-number="2"> </td>
<td id="file-phpcs-xml-LC2" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">ruleset</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress Coding Standards<span class="pl-pds">&#8220;</span></span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L3" class="blob-num js-line-number" data-line-number="3"> </td>
<td id="file-phpcs-xml-LC3" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">description</span>&gt;WooCommerce extension PHP_CodeSniffer ruleset.&lt;/<span class="pl-ent">description</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L4" class="blob-num js-line-number" data-line-number="4"> </td>
<td id="file-phpcs-xml-LC4" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-phpcs-xml-L5" class="blob-num js-line-number" data-line-number="5"> </td>
<td id="file-phpcs-xml-LC5" class="blob-code blob-code-inner js-file-line"><span class="pl-c">&lt;!– Exclude paths –&gt;</span></td>
</tr>
<tr>
<td id="file-phpcs-xml-L6" class="blob-num js-line-number" data-line-number="6"> </td>
<td id="file-phpcs-xml-LC6" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude-pattern</span>&gt;tests/&lt;/<span class="pl-ent">exclude-pattern</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L7" class="blob-num js-line-number" data-line-number="7"> </td>
<td id="file-phpcs-xml-LC7" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude-pattern</span>&gt;woo-includes/woo-functions.php&lt;/<span class="pl-ent">exclude-pattern</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L8" class="blob-num js-line-number" data-line-number="8"> </td>
<td id="file-phpcs-xml-LC8" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude-pattern</span>&gt;woo-includes/class-wc-dependencies.php&lt;/<span class="pl-ent">exclude-pattern</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L9" class="blob-num js-line-number" data-line-number="9"> </td>
<td id="file-phpcs-xml-LC9" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude-pattern</span>&gt;*/node_modules/*&lt;/<span class="pl-ent">exclude-pattern</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L10" class="blob-num js-line-number" data-line-number="10"> </td>
<td id="file-phpcs-xml-LC10" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude-pattern</span>&gt;*/vendor/*&lt;/<span class="pl-ent">exclude-pattern</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L11" class="blob-num js-line-number" data-line-number="11"> </td>
<td id="file-phpcs-xml-LC11" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-phpcs-xml-L12" class="blob-num js-line-number" data-line-number="12"> </td>
<td id="file-phpcs-xml-LC12" class="blob-code blob-code-inner js-file-line"><span class="pl-c">&lt;!– Configs –&gt;</span></td>
</tr>
<tr>
<td id="file-phpcs-xml-L13" class="blob-num js-line-number" data-line-number="13"> </td>
<td id="file-phpcs-xml-LC13" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">config</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>minimum_supported_wp_version<span class="pl-pds">&#8220;</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>4.7<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L14" class="blob-num js-line-number" data-line-number="14"> </td>
<td id="file-phpcs-xml-LC14" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">config</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>testVersion<span class="pl-pds">&#8220;</span></span> <span class="pl-e">value</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>5.6-<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L15" class="blob-num js-line-number" data-line-number="15"> </td>
<td id="file-phpcs-xml-LC15" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-phpcs-xml-L16" class="blob-num js-line-number" data-line-number="16"> </td>
<td id="file-phpcs-xml-LC16" class="blob-code blob-code-inner js-file-line"><span class="pl-c">&lt;!– Rules –&gt;</span></td>
</tr>
<tr>
<td id="file-phpcs-xml-L17" class="blob-num js-line-number" data-line-number="17"> </td>
<td id="file-phpcs-xml-LC17" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">rule</span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress-Extra<span class="pl-pds">&#8220;</span></span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L18" class="blob-num js-line-number" data-line-number="18"> </td>
<td id="file-phpcs-xml-LC18" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Generic.Commenting.DocComment.SpacingAfter<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L19" class="blob-num js-line-number" data-line-number="19"> </td>
<td id="file-phpcs-xml-LC19" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Generic.Files.LineEndings.InvalidEOLChar<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L20" class="blob-num js-line-number" data-line-number="20"> </td>
<td id="file-phpcs-xml-LC20" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L21" class="blob-num js-line-number" data-line-number="21"> </td>
<td id="file-phpcs-xml-LC21" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>PEAR.Functions.FunctionCallSignature<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L22" class="blob-num js-line-number" data-line-number="22"> </td>
<td id="file-phpcs-xml-LC22" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Squiz.Commenting<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L23" class="blob-num js-line-number" data-line-number="23"> </td>
<td id="file-phpcs-xml-LC23" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Squiz.PHP.DisallowSizeFunctionsInLoops.Found<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L24" class="blob-num js-line-number" data-line-number="24"> </td>
<td id="file-phpcs-xml-LC24" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Squiz.WhiteSpace<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L25" class="blob-num js-line-number" data-line-number="25"> </td>
<td id="file-phpcs-xml-LC25" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.Arrays<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L26" class="blob-num js-line-number" data-line-number="26"> </td>
<td id="file-phpcs-xml-LC26" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.Files.FileName<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L27" class="blob-num js-line-number" data-line-number="27"> </td>
<td id="file-phpcs-xml-LC27" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.NamingConventions<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L28" class="blob-num js-line-number" data-line-number="28"> </td>
<td id="file-phpcs-xml-LC28" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.Security.ValidatedSanitizedInput.MissingUnslash<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L29" class="blob-num js-line-number" data-line-number="29"> </td>
<td id="file-phpcs-xml-LC29" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.WP.I18n.NonSingularStringLiteralText<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L30" class="blob-num js-line-number" data-line-number="30"> </td>
<td id="file-phpcs-xml-LC30" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.WhiteSpace<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L31" class="blob-num js-line-number" data-line-number="31"> </td>
<td id="file-phpcs-xml-LC31" class="blob-code blob-code-inner js-file-line">&lt;/<span class="pl-ent">rule</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L32" class="blob-num js-line-number" data-line-number="32"> </td>
<td id="file-phpcs-xml-LC32" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-phpcs-xml-L33" class="blob-num js-line-number" data-line-number="33"> </td>
<td id="file-phpcs-xml-LC33" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">rule</span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WooCommerce-Core<span class="pl-pds">&#8220;</span></span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L34" class="blob-num js-line-number" data-line-number="34"> </td>
<td id="file-phpcs-xml-LC34" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Core.Commenting.CommentTags.AuthorTag<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L35" class="blob-num js-line-number" data-line-number="35"> </td>
<td id="file-phpcs-xml-LC35" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>WordPress.PHP.DontExtract<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L36" class="blob-num js-line-number" data-line-number="36"> </td>
<td id="file-phpcs-xml-LC36" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Generic.Arrays.DisallowShortArraySyntax<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L37" class="blob-num js-line-number" data-line-number="37"> </td>
<td id="file-phpcs-xml-LC37" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude</span> <span class="pl-e">name</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>Generic.WhiteSpace.ScopeIndent.Incorrect<span class="pl-pds">&#8220;</span></span> /&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L38" class="blob-num js-line-number" data-line-number="38"> </td>
<td id="file-phpcs-xml-LC38" class="blob-code blob-code-inner js-file-line">&lt;/<span class="pl-ent">rule</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L39" class="blob-num js-line-number" data-line-number="39"> </td>
<td id="file-phpcs-xml-LC39" class="blob-code blob-code-inner js-file-line"> </td>
</tr>
<tr>
<td id="file-phpcs-xml-L40" class="blob-num js-line-number" data-line-number="40"> </td>
<td id="file-phpcs-xml-LC40" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">rule</span> <span class="pl-e">ref</span>=<span class="pl-s"><span class="pl-pds">&#8220;</span>PHPCompatibility<span class="pl-pds">&#8220;</span></span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L41" class="blob-num js-line-number" data-line-number="41"> </td>
<td id="file-phpcs-xml-LC41" class="blob-code blob-code-inner js-file-line">&lt;<span class="pl-ent">exclude-pattern</span>&gt;tests/&lt;/<span class="pl-ent">exclude-pattern</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L42" class="blob-num js-line-number" data-line-number="42"> </td>
<td id="file-phpcs-xml-LC42" class="blob-code blob-code-inner js-file-line">&lt;/<span class="pl-ent">rule</span>&gt;</td>
</tr>
<tr>
<td id="file-phpcs-xml-L43" class="blob-num js-line-number" data-line-number="43"> </td>
<td id="file-phpcs-xml-LC43" class="blob-code blob-code-inner js-file-line">&lt;/<span class="pl-ent">ruleset</span>&gt;</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
</div>
</div>
</div>
<p>&nbsp;</p>
</div>
</div>
<p>To install locally:</p>
<ol>
<li>Go to your product directory.</li>
<li>Install WooCommerce sniffs with <code>composer require woocommerce/woocommerce-sniffs</code>.</li>
<li>Put <code>phpcs.xml</code> above in the product directory.</li>
<li>Run <code>./vendor/bin/phpcs --warning-severity=0 -s --ignore-annotations --extensions=php,html .</code> .</li>
</ol>
<h3 id="error-1009">error_pbs_test_installing</h3>
<p>Cannot install the product. Most common issue is the top directory of the zip does not match its slug.</p>
<h3 id="error-1010">error_pbs_test_activating</h3>
<p>Cannot activate the product. Refer to the build output for more details.</p>
<h3 id="error-1011">error_pbs_test_deactivating</h3>
<p>Cannot deactivate the product. Refer to the build output for more details.</p>
<h3 id="error-1012">error_pbs_test_host_plan_installing</h3>
<p>This error means that your product is incompatible with other products in the host plan. Refer to the build output for more details.</p>
<h3 id="error-1013">error_pbs_test_host_plan_activating</h3>
<p>This error means that your product is incompatible with other products in the host plan. Refer to the build output for more details.</p>
<h3 id="error-1014">error_pbs_test_host_plan_deactivating</h3>
<p>This error means that your product is incompatible with other products in the host plan. Refer to the build output for more details.</p>
<h3 id="error-1015">error_pbs_missing_theme_info_file</h3>
<p>Your theme is missing the theme info file <code>theme_info.txt</code> under the root directory.</p>
<h3 id="error-1016">error_pbs_incomplete_theme_info</h3>
<p>Your theme info file <code>theme_info.txt</code> contains malformed data structure. It should contain the product ID, hash and main file, all separated by new lines. For example:</p>
<pre>887931
2429c1dde521031cd053886b15844bbf
storechild/style.css
</pre>
<h3 id="error-1017">error_pbs_incomplete_theme_header</h3>
<p>Your theme main file contains malformed data structure. Provide <code>Theme Name</code>, <code>Version</code>, and the <code>Woo</code> headers in your main file.</p>
<h3 id="error-1018">error_pbs_incomplete_plugin_header</h3>
<p>Your plugin main file contains malformed data structure. Provide <code>Plugin Name</code>, <code>Version</code>, and the <code>Woo</code> headers in your main file.</p>
<h3 id="error-1019">error_pbs_invalid_woo_header</h3>
<p>Your product main file contains an invalid Woo header structure. Use the format <code>ID:HASH</code>. For example:</p>
<pre> * Woo: 390890:911c438934af094c2b38d5560b9f50f3
</pre>
<h3 id="error-1020">error_pbs_invalid_id</h3>
<p>Your product main file contains an invalid product ID in the Woo header.</p>
<h3 id="error-1021">error_pbs_invalid_hash</h3>
<p>Your product main file contains an invalid hash in the Woo header.</p>
<h3 id="error-1022">error_pbs_missing_main_file</h3>
<p>Your product is missing the main file.</p>
<h3 id="error-1023">error_pbs_missing_changelog_file</h3>
<p>Your product is missing the <code>changelog.txt</code> file.</p>
<h3 id="error-1024">error_pbs_product_version_mismatch</h3>
<p>The version in your product’s main file does not match with the provided version in <code>changelog.txt</code>.</p>
<h3 id="error-1025">error_pbs_invalid_changelog_format</h3>
<p>Your product contains malformed <code>changelog.txt</code> structure. Refer to changelog.txt as an example.</p><p>The post <a href="https://help.codibu.com/blog/woocommerce-plugin-developer-handbook/">WooCommerce Plugin Developer Handbook</a> first appeared on <a href="https://help.codibu.com">CODIBU</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://help.codibu.com/blog/woocommerce-plugin-developer-handbook/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
