009eecde by Jeff Balicki

woo

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 9959f24a
......@@ -4,7 +4,6 @@ add_filter( 'woocommerce_account_menu_items', 'misha_rename_downloads' );
function misha_rename_downloads( $menu_links ){
// $menu_links[ 'TAB ID HERE' ] = 'NEW TAB NAME HERE';
$menu_links[ 'dashboard' ] = 'My Account';
$menu_links[ 'edit-address' ] = 'Address';
......@@ -64,8 +63,6 @@ add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );
// ----- validate password match on the registration page
function registration_errors_validation($reg_errors, $sanitized_user_login, $user_email) {
global $woocommerce;
......@@ -146,20 +143,20 @@ function my_remove_cart_product_image() {
add_action('acf/save_post', 'create_and_attach_woocommerce_product', 1);
add_action('wp_after_insert_post', 'create_and_attach_woocommerce_product', 1);
function create_and_attach_woocommerce_product( $course_id ) {
$post = get_post($course_id);
if ( !wp_is_post_autosave( $post ) && $post->post_status !== 'auto-draft' && !wp_is_post_revision( $course_id ) ) {
if ( get_post_type($course_id) == 'sfwd-courses') {
error_log('create_and_attach_woocommerce_product');
// Set the product data
if(!get_post_meta( $course_id, '_woocommerce_product', true )){
$product_data = array(
'post_title' => get_the_title( $course_id ),
'post_type' => 'product',
'post_status' => 'publish'
);
// Insert the product
$product_id = wp_insert_post( $product_data );
update_post_meta( $course_id, '_woocommerce_product', $product_id );
// Set the product type
......@@ -168,33 +165,24 @@ function create_and_attach_woocommerce_product( $course_id ) {
// Set the related_course
$related_course = array($course_id);
update_post_meta( $product_id, '_related_course', $related_course);
// Set the prices
update_post_meta( $product_id, '_regular_price', $price );
update_post_meta( $product_id, '_price', $price );
update_post_meta( $product_id, '_role_based_price',$sp );
}else{
$product_id = get_post_meta( $course_id, '_woocommerce_product', true );
$product_data = array(
'ID' => $product_id,
'post_title' => get_the_title( $course_id )
);
$product = wp_update_post( $product_data );
}
}
add_action( 'wp_after_insert_post', 'my_wp_after_insert_post', 10, 4 );
function my_wp_after_insert_post( $post_id, $post, $update, $post_before ) {
if ( 'publish' !== $post->post_status || ( $post_before && 'publish' === $post_before->post_status ) || wp_is_post_revision( $post_id )) {
if ( get_post_type($post_id) == 'sfwd-courses') {
error_log('woocommerce_learndash_product');
learndash_update_setting($post_id, 'sfwd-courses_course_price_type', 'closed' );
$product_id = get_post_meta($post_id, '_woocommerce_product',true);
learndash_update_setting($post_id, 'sfwd-courses_certificate', 426 );
learndash_update_setting($course_id, 'sfwd-courses_course_price_type', 'closed' );
learndash_update_setting($course_id, 'sfwd-courses_certificate', 426 );
if($product_id !=""){
$courses_custom_button_url = learndash_update_setting($post_id, 'sfwd-courses_custom_button_url', get_site_url().'/cart/?add-to-cart='.$product_id );
$courses_custom_button_url = learndash_update_setting($course_id, 'sfwd-courses_custom_button_url', get_site_url().'/cart/?add-to-cart='.$product_id );
}
$price = get_post_meta($post_id, 'program_info_cost_&_dates_0_cost',true );
$price = get_post_meta($course_id, 'program_info_cost_&_dates_0_cost',true );
if($price !=""){
learndash_update_setting($post_id, 'sfwd-courses_course_price', $price );
learndash_update_setting($course_id, 'sfwd-courses_course_price', $price );
}
$staff_price = get_post_meta($post_id, 'program_info_cost_&_dates_0_cost_staff',true );
$staff_price = get_post_meta($course_id, 'program_info_cost_&_dates_0_cost_staff',true );
if($staff_price !=""){
$sp = array('staff' =>array('regular_price' => $staff_price));
update_post_meta( $product_id, '_regular_price', $price );
......@@ -203,9 +191,10 @@ function my_wp_after_insert_post( $post_id, $post, $update, $post_before ) {
}
}
}
}
// Redirect to All posts dashboard after post update/publish
function webroomtech_redirect_to_post_list() {
global $pagenow;
......