Last active
November 27, 2019 18:07
-
-
Save anthonysbrown/100c7e6a99efd3dcd3793051a38d941f to your computer and use it in GitHub Desktop.
Woocommerce check page ID and if not there then set it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Function: Check Pages to see if WooCommerce pages are set. | |
Description: Woocommerce check page ID and if not there then set it. Sometimes the woocommerce pages because unset for some reasons, use this to check it and set it automatically. | |
Params: None | |
Author: Anthony Brown (Codeable) | |
Email: [email protected] | |
*/ | |
function check_wp_pages_installed(){ | |
#default options for all woo pages | |
$options = array( 'shop'=>'woocommerce_shop_page_id', | |
'cart'=>'woocommerce_cart_page_id', | |
'checkout'=>'woocommerce_checkout_page_id', | |
'myaccount'=>'woocommerce_myaccount_page_id' , | |
'terms'=> 'woocommerce_terms_page_id' | |
); | |
#these are the default page IDs for each area of woocommerce, leave blank to not set. | |
$defaults = array( 'shop'=>75327, | |
'cart'=>6, | |
'checkout'=>7, | |
'myaccount'=>72845, | |
'terms'=>'' | |
); | |
#this is an array of what is currently in the database | |
$current = array( 'shop'=> get_option( 'woocommerce_shop_page_id' ), | |
'cart'=>get_option( 'woocommerce_cart_page_id' ), | |
'checkout'=>get_option( 'woocommerce_checkout_page_id' ), | |
'myaccount'=>get_option( 'woocommerce_myaccount_page_id' ), | |
'terms'=>get_option( 'woocommerce_terms_page_id' ) | |
); | |
#loop through each set value to see if it exists and it doesn't then set it. | |
foreach($current as $page=>$value){ | |
if($value == '' && $defaults[$page] != ''){ | |
update_option($options[$page], $defaults[$page]); | |
} | |
} | |
} | |
add_action('wp','check_wp_pages_installed'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment