File: /home/qirgxuo4hkuv/public_html/shovago.com/wp-content/themes/ShovaGo copy/functions.php
<?php
// Allow redirection, even if my theme starts to send output to the browser
add_action('init', 'do_output_buffer');
function do_output_buffer() {
ob_start();
}
require get_template_directory() . '/inc/functions/template-functions.php';
require get_template_directory() . '/inc/functions/assets-functions.php';
require get_template_directory() . '/inc/metabox-config.php';
require get_template_directory() . '/inc/meta-box/meta-box.php';
require get_template_directory() . '/inc/shovago-options.php';
add_filter ( 'add_to_cart_redirect', 'redirect_to_checkout' );
function redirect_to_checkout() {
global $woocommerce;
// Remove the default `Added to cart` message
wc_clear_notices();
return $woocommerce->cart->get_checkout_url();
}
function cart_fix_css() {
if ( is_checkout() ) {
?>
<style type="text/css">.cart { width: auto; }</style>
<?php
}
}
add_action( 'wp_head', 'cart_fix_css' );
function GaloAnnainit() {
$labels =
array(
'name' => __( 'قالو عنا', 'al7al_text' ),
'singular_name' => __( 'قالو عنا', 'al7al_text' ),
'add_new' => __( 'إضافة قالو عنا', 'al7al_text' ),
'add_new_item' => __( 'إضافة قالو عنا', 'al7al_text' ),
'edit_item' => __( 'تعديل قالو عنا', 'al7al_text' ),
'new_item' => __( 'إضافة قالو عنا', 'al7al_text' ),
'all_items' => __( 'كل ماقالو عنا', 'al7al_text' ),
'view_item' => __( 'كل ماقالو عنا', 'al7al_text' ),
'search_items' => __( 'ابحث عن ماقالو عنا', 'al7al_text' ),
'not_found' => __( 'لم يقولو عنا شئ', 'al7al_text' ),
'not_found_in_trash' => __( 'لم يقولو عنا شئ', 'al7al_text' ),
'parent_item_colon' => '',
'menu_name' => __( 'قالو عنا', 'al7al_text' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'has_archive' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'GaloAnna'),
'query_var' => true,
'menu_icon' => 'dashicons-format-video',
'supports' =>
array(
'title',
'excerpt',
'custom-fields',
'thumbnail',
)
);
register_post_type( 'GaloAnna', $args );
}
add_action( 'init', 'GaloAnnainit' );
// HERE define your field label name
function get_field_label_name(){
return __( "" );
}
// Add a custom product note below product meta in single product pages
add_action('woocommerce_before_add_to_cart_button', 'my_product_custom_field', 100 );
function my_product_custom_field() {
echo '<div class="form-group">';
echo '<label>الرابط [يجب على الحساب ان يكون عام و ليس خاص]<abbr class="required" title="مطلوب">*</abbr></label>';
woocommerce_form_field('custom_field1', array(
'type' => 'text',
'label' => get_field_label_name(),
'required' => true,
) , '');
echo '</div>';
}
function url_account_myhot() {
if ( empty( $_REQUEST['custom_field1'] ) ) {
wc_add_notice( __( 'من فضلك ادخل رابط الحساب', 'woocommerce' ), 'error' );
return false;
}
return true;
}
add_action( 'woocommerce_add_to_cart_validation', 'url_account_myhot', 10, 3 );
// Add custom field value to cart item data
add_filter( 'woocommerce_add_cart_item_data', 'custom_field_value_to_cart_item_data', 20, 2 );
function custom_field_value_to_cart_item_data( $cart_item_data, $product_id ){
if( isset($_POST['custom_field1']) && ! empty($_POST['custom_field1']) ){
$cart_item_data['custom_data'] = sanitize_textarea_field( $_POST['custom_field1'] );
}
return $cart_item_data;
}
// Field Validation
add_action('woocommerce_before_add_to_cart_button', 'my_product_custom_fields');
function my_product_custom_fields() {
if ( isset($_POST['custom_field1']) && empty($_POST['custom_field1']) )
wc_add_notice( __( 'من فضلك قم بإضافة رابط حسابك' ), 'error' );
}
// Display custom cart item data in cart
add_filter( 'woocommerce_get_item_data', 'display_custom_item_data', 10, 2 );
function display_custom_item_data( $cart_item_data, $cart_item ) {
if ( isset( $cart_item['custom_data'] ) ){
$cart_item_data[] = array(
'name' => get_field_label_name(),
'value' => $cart_item['custom_data']
);
}
return $cart_item_data;
}
// Save / Display custom field value as custom order item meta data
add_action( 'woocommerce_checkout_create_order_line_item', 'custom_field_update_order_item_meta', 20, 4 );
function custom_field_update_order_item_meta( $item, $cart_item_key, $values, $order ) {
if( isset($values['custom_data']) ){
$item->update_meta_data( __('الرابط'), $values['custom_data'] );
}
}
/*** Settings POSTS ***/
add_filter( 'woocommerce_checkout_fields', 'myhot_remove_fields', 9999 );
function myhot_remove_fields( $woo_checkout_fields_array ) {
unset( $woo_checkout_fields_array['billing']['billing_first_name'] );
unset( $woo_checkout_fields_array['billing']['billing_last_name'] );
unset( $woo_checkout_fields_array['billing']['billing_phone'] );
unset( $woo_checkout_fields_array['order']['order_comments'] ); // remove order notes
// and to remove the billing fields below
unset( $woo_checkout_fields_array['billing']['billing_company'] ); // remove company field
unset( $woo_checkout_fields_array['billing']['billing_country'] );
unset( $woo_checkout_fields_array['billing']['billing_address_1'] );
unset( $woo_checkout_fields_array['billing']['billing_address_2'] );
unset( $woo_checkout_fields_array['billing']['billing_city'] );
unset( $woo_checkout_fields_array['billing']['billing_state'] ); // remove state field
unset( $woo_checkout_fields_array['billing']['billing_postcode'] ); // remove zip code field
return $woo_checkout_fields_array;
}
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_title', 5 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_rating', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_price', 10 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_excerpt', 20 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_meta', 40 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_sharing', 50 );
remove_action( 'woocommerce_single_product_summary', 'woocommerce_template_single_images', 50 );
grant_super_admin(1);